tar

Pack files into an archive or unpack one

What it does

tar gathers files and folders into one archive. Flags are combined: -c creates, -x extracts, -t lists the contents, -z compresses or decompresses with gzip (hence .tar.gz), and -f names the archive. f goes last because the file name follows it.

An archive unpacks into the current folder; -C <folder> picks another. -v prints file names as it works. Modern tar detects compression when unpacking on its own, but -z does no harm.

Careful. Unpacking silently overwrites files with the same names. If you are not sure what is inside, look with tar -tzf first.

Syntax

tar -czf <archive>.tar.gz <what>…
tar -xzf <archive>.tar.gz
tar -xzf <archive>.tar.gz -C <folder>
tar -tzf <archive>.tar.gz

Examples

Related commands

Practise · All commands