Create a compressed archive of a directory
Low risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Packs a directory into a single compressed archive for backup or transfer — tar.gz on macOS/Linux, zip on Windows.
filesarchivecompressbackup
Parameters
Directory to archive.
Output archive path, e.g. "backup.tar.gz" (or "backup.zip" on Windows).
Commands
Check the directory's size before archiving
du -sh "<directory>"Create a gzip-compressed tar archive of the directory
tar -czf "<archive>" "<directory>"Verification
tar -tzf "<archive>" | headThe archive lists the directory's files without errors.
Undo
Remove the created archive; the original directory is untouched
rm "<archive>"Pitfalls
- Archiving with an absolute path stores the full path inside the archive; cd to the parent and archive the relative name instead.
- Do not place the output archive inside the directory being archived, or tar may try to archive itself.
- Compress-Archive skips hidden and in-use files in some cases and has a 2 GB per-file limit on older PowerShell versions.