Archive With Exclusions Using tar
Create a compressed archive while omitting build output and VCS data.
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
!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
- tar.1.en.html manual page (Debian bookworm)Evidence: Documents GNU tar --exclude patterns and archive creation.
Last verified: 2026-10-13 · Category: Files & Folders
06Related solutions
Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Extract a .tar.gz archive with tar
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Check free disk space on each filesystem with df
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.