Is there a simple shell command/script that supports excluding certain files/folders from being archived?
I have a directory that need to be archived with a sub dire
If you are trying to exclude Version Control System (VCS) files, tar already supports two interesting options about it! :)
This option excludes files and directories used by following version control systems: CVS
, RCS
, SCCS
, SVN
, Arch
, Bazaar
, Mercurial
, and Darcs
.
As of version 1.32, the following files are excluded:
CVS/
, and everything under itRCS/
, and everything under itSCCS/
, and everything under it.git/
, and everything under it.gitignore
.gitmodules
.gitattributes
.cvsignore
.svn/
, and everything under it.arch-ids/
, and everything under it{arch}/
, and everything under it=RELEASE-ID
=meta-update
=update
.bzr
.bzrignore
.bzrtags
.hg
.hgignore
.hgrags
_darcs
When archiving directories that are under some version control system (VCS), it is often convenient to read exclusion patterns from this VCS' ignore files (e.g. .cvsignore
, .gitignore
, etc.) This option provide such possibility.
Before archiving a directory, see if it contains any of the following files: cvsignore
, .gitignore
, .bzrignore
, or .hgignore
. If so, read ignore patterns from these files.
The patterns are treated much as the corresponding VCS would treat them, i.e.:
.cvsignore
Contains shell-style globbing patterns that apply only to the directory where this file resides. No comments are allowed in the file. Empty lines are ignored.
.gitignore
Contains shell-style globbing patterns. Applies to the directory where .gitfile
is located and all its subdirectories.
Any line beginning with a #
is a comment. Backslash escapes the comment character.
.bzrignore
Contains shell globbing-patterns and regular expressions (if prefixed with RE:
(16). Patterns affect the directory and all its subdirectories.
Any line beginning with a #
is a comment.
.hgignore
Contains posix regular expressions(17). The line syntax: glob
switches to shell globbing patterns. The line syntax: regexp
switches back. Comments begin with a #
. Patterns affect the directory and all its subdirectories.
tar -czv --exclude-vcs --exclude-vcs-ignores -f path/to/my-tar-file.tar.gz path/to/my/project/