tar

Pack a folder into one compressed file, look inside it and unpack it somewhere else.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • tar -czf logs.tar.gz logs
  • tar -tzf logs.tar.gz
  • mkdir restore && tar -xzf logs.tar.gz -C restore
  • ls restore/logs
  • tar -cvf logs.tar logs

How it works

tar packs many files into one archive. Pick what to do (-c create, -t list, -x extract), add -z to compress with gzip (the .gz), and -f with the archive's name.

Backups, downloads and releases are often .tar.gz files: tar -xzf is the command to open them.

Syntax

tar -c|-t|-x [-z] [-v] -f ARCHIVE [FILE...]

Options

OptionWhat it does
-ccreate an archive
-xextract an archive
-tlist what is inside
-zcompress / decompress with gzip (.gz)
-fthe archive file (the name comes right after)
-vshow each file as it goes
-Cextract into another folder

Good to know

  • Read the letters as a sentence: -czf = create, gzip, file.
  • Look inside with -t before extracting: an archive can spill files into the current folder.