Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

$ 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.