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.gzExamples
Pack the folder site into the compressed archive backup.tar.gz
tar -czf backup.tar.gz sitesame as:
tar czf backup.tar.gz site,tar -zcf backup.tar.gz sitetar— the archiver-c— create an archive-z— compress with gzip-f backup.tar.gz— the archive name; f comes lastsite— what to pack
Unpack backup.tar.gz into the current folder
tar -xzf backup.tar.gzsame as:
tar xzf backup.tar.gz,tar -zxf backup.tar.gz,tar -xf backup.tar.gz,tar xf backup.tar.gztar— the archiver-x— extract-z— the archive is gzipped-f backup.tar.gz— which archive