archive

tar

Bundles multiple files into a single archive and can transparently compress with gzip, bzip2, or xz. The default archive format on Linux.

tar [OPTION]... [FILE]...

Common flags

Flag Purpose
-c Create a new archive
-x Extract from an archive
-t List archive contents
-f Archive file to read/write (must be last before the filename)
-v Verbose -- list files as they are processed
-z Filter through gzip
-j Filter through bzip2
-J Filter through xz

Examples

tar -czvf site.tar.gz site/

Create a gzip-compressed archive of a directory

tar -xzvf site.tar.gz

Extract a gzipped tarball

tar -tf release.tar.gz

List contents without extracting

tar -xJf pkg.tar.xz -C /opt

Extract an xz-compressed archive into /opt

Gotcha

-f must be the last flag in a bundle like -czvf because it takes the filename that follows it; a misplaced -f is a classic mistake.

Related commands

← All Linux commands · Linux cheat sheet