Command library / tar
tar
Create or extract archive files
Bundles many files into one archive, or unpacks one. The classic combo is c+z+v+f (create, gzip-compress, verbose, filename) to make a .tar.gz, and x+z+v+f to unpack one. The letters can be bundled after a single dash, and whichever position 'f' ends up in, the archive filename comes right after it.
Practice tarUsage
tar -xzvf archive.tar.gz
tar -tzvf archive.tar.gz
Options and flags
filesfiles/directories to archive (create mode) — none needed for extract/list
-ccreate a new archive
-xextract from an archive
-tlist an archive's contents without extracting
-zcompress/decompress with gzip (.tar.gz)
-vverbose: list each file as it's processed
-fFILEthe archive file name — almost always the last letter before the name
Examples
tar -czvf backup.tar.gz project/Create a compressed archive of the project/ folder.
tar -xzvf backup.tar.gzUnpack that archive in the current directory.
tar -tzvf backup.tar.gzSee what's inside without extracting anything — check before you unpack an unknown archive.
Common mistakes
-f needs the archive's file name right after it — tar has nothing to extract from without one.