tar

Archive and compress files — the standard Linux backup and packaging tool.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

tar bundles files into an archive. Combined with gzip (-z), bzip2 (-j), or xz (-J) it compresses too. The -C flag changes extraction directory. Always inspect archives with -t before extracting to avoid surprises.

Common flags
FlagMeaning
-c --createCreate a new archive
-x --extractExtract files from an archive
-t --listList archive contents without extracting
-z --gzipCompress/decompress with gzip (.tar.gz)
-j --bzip2Compress/decompress with bzip2 (.tar.bz2)
-J --xzCompress/decompress with xz (.tar.xz) — best compression ratio
-f --fileSpecify archive filename
-v --verboseVerbosely list files processed
-C --directoryChange to directory before extracting
Examples
tar -czf backup-$(date +%F).tar.gz /var/www/htmlCreate date-stamped compressed backup of web root · explain & risk-check →
tar -xzf archive.tar.gz -C /opt/app/Extract archive into /opt/app/ · explain & risk-check →
tar -tzf archive.tar.gz | head -20Preview compressed archive contents before extracting · explain & risk-check →
Pro tip

Exclude directories on archive: `tar --exclude='./logs' --exclude='./.git' -czf archive.tar.gz .`

Related
gzip zip rsync scp find
Open the full explainer →More in Files & Archives

Reference text is hand-written and may be incomplete — check man tar for your version. Test destructive commands on a non-production system first.