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 am compressing list of files like this:

tar cvzf  mycompress.tar.gz /dir1/dir2/file1.txt /dir1/dir2/file2.txt

However when I uncompressed them the directory /dir1/dir2/ is still preserved. How to exclude that?

share|improve this question

migrated from stackoverflow.com Aug 20 '11 at 2:03

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

2 Answers 2

up vote 3 down vote accepted

You can do

tar cz -C /dir1/dir2 -f mycompress.tar.gz file1.txt file2.txt

That will leave out the path information in the archive.

share|improve this answer
    
+1 for clean and straightforward answer. –  djhaskin987 Aug 16 '11 at 13:02

If you want to encrypt only files and not directory (is this that you want to do? I'm not sure), then try to use find to exclude directories:

tar cvzf  mycompress.tar.gz ` find  your_path_starting_point -type f `

(Having files with the same name into different directories could be a problem)

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.