Back Up a Folder to a tar.gz Archive
Compress a whole directory tree into a single file with the built-in tar.
Run `tar -czf backup.tar.gz /path/to/folder` to create a gzip-compressed archive.
01Command
Command
$ tar -czf 项目备份-2026-09-17.tar.gz ~/Projects/站点A02What it does
tar preserves Unix permissions and directory structure in one pass, making it more faithful than zipping files individually. The flags are easy to remember as “create, zip-compressed, file”. Extract later with `tar -xzf` into the same structure; progress can be shown with `-v`.
03Risk
!Warning: By default tar stores absolute paths minus the leading `/` — extract carefully to avoid clobbering the original location. Resources-fork metadata on Mac-specific files may be lost; use `--mac-metadata` (bsdtar on macOS supports it) when fidelity matters.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- tar – Manipulate archivesEvidence: Documents -c create, -z gzip compression, -f file output
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
List Local Time Machine Snapshots with tmutil
See every local APFS Time Machine snapshot on your startup disk and delete ones you no longer need.
Find files larger than 500 MB on Mac
List the biggest files in your home folder that are eating disk space.
Show file extensions for all files on Mac
Make Finder display .pdf, .docx, .png and every other extension at all times.