Excluding Path While Compressing with TAR/GZ

2

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?

neversaint

Posted 2011-08-16T10:11:55.037

Reputation: 285

Answers

4

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.

Nodebody

Posted 2011-08-16T10:11:55.037

Reputation: 251

1

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)

Heisenbug

Posted 2011-08-16T10:11:55.037

Reputation: 645