Useful Tar Command Examples on linux

Tar available parameters:

c Create new archive.
t List content of an archive.
x Extract content of an archive.
f The archive filename is given on the command line.
M The archive can span multiple floppies.
v Print verbose output (slow).
u Add files to archive if they are newer than the copy present in the tar file.
z Compress/decompress files.

Compress a file:

tar cvf file.tar file.log

Compress a folder:

tar cvf path.tar path/

Compress a file with gzip:

tar cvzf file.tar.gz file.log

Compress a folder with gzip:

tar cvzf path.tar.gz path/

Compress a folder with bzip:

tar cjfv path.tar.bz2 path/

Extract gzip archive:

gunzip file.tar.gz

Extract tar archive:

tar xvf file.tar

Extract bz2 archive:

tar -xjf file.tar.bz2

List files of a tar archive:

tar tvf file.tar

More Related Posts