back

Bash Commands: tar

tar options1:

SHORTCUTS TO: gzip | bzip2 | xz | NULL

Uncompressed Archives (.tar)1

To create an uncompressed archive:

tar cvf archiveName.tar folderToBeArchived

To extract an uncompressed archive:

tar xvf archiveName.tar

To list/view archive contents without extracting:

tar tvf archiveName.tar

gzip File Compression Utility (.tgz, .tar.gz)1

To create and compress a gzip archive:

tar cvfz archiveName.tar.gz folderToBeArchived

To extract a gzip archive:

tar xvfz archiveName.tar.gz

To list/view gzip archive contents without extracting:

tar tvfz archiveName.tar.gz

bzip2 File Compression Utility (.bz2, .tbz, .tar.bz2)1

To create and compress a bzip2 archive :

tar cvfj archiveName.tar.bz2 folderToBeArchived

To extract a bzip2 archive:

tar xvfj archiveName.tar.bz2

To list/view bzip2 archive contents without extracting:

tar tvfj archiveName.tar.bz2

xz File Compression Utility (.tar.xz, .txz)2

To create an archive of a directory with xz compression:

tar cfJv archiveName.tar.xz folderToBeArchived

To extract an archive:

tar xfJv archiveName.tar.xz

xz File Compression Utility (.xz)2

To compress a file or directory with xz compression:

xz archiveName.xz destinationFolder # DOES NOT ACTUALLY WORK :( tar -c --xz -f my_archive.tar.xz /some_directory # results in my_archive.tar.xz

To extract a file or directory with the .xz extension:

xz -d archiveName.xz destinationFolder

Footnotes

1. The Geek Stuff: The Ultimate Tar Command Tutorial with 10 Practical Examples
2. PuppyLinux : xz