Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know there are a lot of questions that seems identical, but I haven't found so far my answer.

So let's figure I'm in the current working directory : /test/ I would like to add to an archive 'test.tar.gz' which will be in /test/archive/ all the files that are contained in /test/files/ and then delete this directory files/

I tried :

tar -cz -C archive -f "test.tar.gz" -C files ./* && rm -rf files

But no success.

Any thoughts ?

Thanks ! Nico

share|improve this question

migrated from stackoverflow.com Apr 13 '12 at 0:33

This question came from our site for professional and enthusiast programmers.

    
tar zcvf archive/test.tar.gz -C files/ . && rm -f files/* – dAm2K Apr 12 '12 at 14:40
$ tar -zcvf archive/test.tar.gz files
files/
files/1
files/2
files/3

$ tar -zcvf archive/test.tar.gz -C files .
./
./1
./2
./3

depending on how you want your tar structured.

share|improve this answer

A single command like this will work assuming you are already in /test

(tar -cvf - ./files/* | gzip >./archive/test.tar.gz) && rm -rf files

By using - we are spewing the output of tar command onto stdout and then piping it to gzip which in turn re-directs its output to ./archive

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .