Back Up a Folder to a tar.gz Archive

Compress a whole directory tree into a single file with the built-in tar.

macOSbackupFilesstoragetarLow risk
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/站点A

02What 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

RiskLow risk
!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

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions