Create a compressed archive
Bundles a folder into a single gzip-compressed .tar.gz archive, listing each file as it's added so you can watch what gets included.
Last updated
tar -czvf archive.tar.gz folder/
How it works
-c creates a new archive; -z compresses it with gzip in the same pass instead of requiring a separate gzip step afterward; -v lists each file as it's added, handy for confirming nothing unexpected got swept in; -f archive.tar.gz names the output file and, like on extraction, must be the last flag in the cluster since the next argument is read as that filename. folder/ is the source being archived — one path here, but tar happily accepts several files or directories in a row.
Compressing in the same pass (rather than tar-then-gzip as two steps) is both simpler to type and avoids leaving an uncompressed intermediate .tar file lying around, which matters when archiving anything large.
Watch out for
- →The trailing slash on folder/ is cosmetic — tar archives the directory and its contents the same either way. What actually matters is the exact path you pass, since that's stored (and later restored) verbatim, including any leading directory components.
- →Run tar from a directory ABOVE the folder you're archiving (or cd into it first) if you don't want your full local path baked into every entry — otherwise anyone extracting it later reproduces your original directory structure exactly.
- →gzip compression is single-threaded and can be noticeably slow on very large archives; GNU tar's --use-compress-program=pigz (if installed) parallelizes it, and -J switches to xz compression instead for a smaller archive at the cost of slower compression time.