Archive With Exclusions Using tar

Create a compressed archive while omitting build output and VCS data.

LinuxFilesarchivecompressLow risk
Run tar --exclude='./node_modules' -czf app.tgz . to archive without that directory.

01Command

Command
$ tar --exclude='./node_modules' --exclude='./.git' -czf app.tgz .

02What it does

tar with --exclude lets you capture exactly the files worth keeping, which keeps backups and support bundles small and avoids leaking .git or secrets. It is precise, repeatable and scriptable, unlike manually selecting files in an archive utility.

03Risk

RiskLow risk
RequirementsPreinstalled on Linux (GNU tar)
!Warning: Exclude patterns are matched against stored paths; include the leading ./ or use --exclude-vcs to be safe.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Files & Folders

06Related solutions