From INIwiki
Jump to: navigation, search


[edit] Several Tar commands I use

[edit] Create a tar.gz file from a directory keeping all permissions:

tar -pczf name_of_your_archive.tar.gz /path/to/directory
Add the v switch to see verbose.  IE: tar -pczvf

[edit] View the contents of the tar.gz:

tar -tzf  name_of_your_archive.tar.gz

[edit] Exclude some directories

Use the --exclude= flag

tar --exclude=/path/to/exclude -pcjvf name_of_your_archive.tgz2 /path/to/backup

[edit] Exclude some file types

Use the --exclude= flag

tar --exclude=/path/to/exclude/*.jpg -pcjvf name_of_your_archive.tgz2 /path/to/backup

or multiple extensions

tar --exclude=/path/to/exclude/*.jpg --exclude=/path/to/exclude/*.png -pcjvf name_of_your_archive.tgz2 /path/to/backup


tar --exclude=./*.jpeg --exclude=./*.jpg -pcjvf test.tgz2 ./

Compression notes:

[edit] To pack and compress:

using gzip:

tar -czf packed_files.tgz file_to_pack1 file_to_pack2 ...

using bzip2:

tar -cjf packed_files.tbz2 file_to_pack1 file_to_pack2 ...

using compress:

tar -cZf packed_files.tar.Z file_to_pack1 file_to_pack2 ...

using some other arbitrary compression utility that works as a filter:

tar --use-compress-program=name_of_program -cf packed_files.tar.XXX file_to_pack1 file_to_pack2 ... 

[edit] To uncompress and unpack:

a gzip compressed tar file:

tar -xzf file_to_unpack.tar.gz

a bzip2 compressed tar file:

tar -xjf file_to_unpack.tar.bz2


tar -xjf file_to_unpack.tbz2

I have seen this named erroneously tgz2 use the bzip operation usually

tar -xjf file_to_unpack.tgz2

a compress compressed tar file:

tar -xZf file_to_unpack.tar.Z

an arbitrary-compression-utility-compressed tar file:

tar --use-compress-program=name_of_program -xf file_to_unpack.tar.XXX 
Some versions of tar use the -y switch to invoke bzip2 rather than -j.

[edit] References:

Personal tools