tar: exclude

1 
1 6.4 Excluding Some Files
1 ========================
1 
1 To avoid operating on files whose names match a particular pattern, use
1 the '--exclude' or '--exclude-from' options.
1 
1 '--exclude=PATTERN'
1      Causes 'tar' to ignore files that match the PATTERN.
1 
1    The '--exclude=PATTERN' option prevents any file or member whose name
1 matches the shell wildcard (PATTERN) from being operated on.  For
1 example, to create an archive with all the contents of the directory
1 'src' except for files whose names end in '.o', use the command 'tar -cf
1 src.tar --exclude='*.o' src'.
1 
1    You may give multiple '--exclude' options.
1 
1 '--exclude-from=FILE'
1 '-X FILE'
1      Causes 'tar' to ignore files that match the patterns listed in
1      FILE.
1 
1    Use the '--exclude-from' option to read a list of patterns, one per
1 line, from FILE; 'tar' will ignore files matching those patterns.  Thus
1 if 'tar' is called as 'tar -c -X foo .' and the file 'foo' contains a
1 single line '*.o', no files whose names end in '.o' will be added to the
1 archive.
1 
1    Notice, that lines from FILE are read verbatim.  One of the frequent
1 errors is leaving some extra whitespace after a file name, which is
1 difficult to catch using text editors.
1 
1    However, empty lines are OK.
1 
1    When archiving directories that are under some version control system
1 (VCS), it is often convenient to read exclusion patterns from this VCS'
1 ignore files (e.g.  '.cvsignore', '.gitignore', etc.)  The following
1 options provide such possibility:
1 
1 '--exclude-vcs-ignores'
1      Before archiving a directory, see if it contains any of the
1      following files: 'cvsignore', '.gitignore', '.bzrignore', or
1      '.hgignore'.  If so, read ignore patterns from these files.
1 
1      The patterns are treated much as the corresponding VCS would treat
1      them, i.e.:
1 
1      '.cvsignore'
1           Contains shell-style globbing patterns that apply only to the
1           directory where this file resides.  No comments are allowed in
1           the file.  Empty lines are ignored.
1 
1      '.gitignore'
1           Contains shell-style globbing patterns.  Applies to the
1           directory where '.gitfile' is located and all its
1           subdirectories.
1 
1           Any line beginning with a '#' is a comment.  Backslash escapes
1           the comment character.
1 
1      '.bzrignore'
1           Contains shell globbing-patterns and regular expressions (if
1           prefixed with 'RE:'(1).  Patterns affect the directory and all
1           its subdirectories.
1 
1           Any line beginning with a '#' is a comment.
1 
1      '.hgignore'
1           Contains posix regular expressions(2).  The line 'syntax:
1           glob' switches to shell globbing patterns.  The line 'syntax:
1           regexp' switches back.  Comments begin with a '#'.  Patterns
1           affect the directory and all its subdirectories.
1 
1 '--exclude-ignore=FILE'
1      Before dumping a directory, 'tar' checks if it contains FILE.  If
1      so, exclusion patterns are read from this file.  The patterns
1      affect only the directory itself.
1 
1 '--exclude-ignore-recursive=FILE'
1      Same as '--exclude-ignore', except that the patterns read affect
1      both the directory where FILE resides and all its subdirectories.
1 
1 '--exclude-vcs'
1      Exclude files and directories used by following version control
1      systems: 'CVS', 'RCS', 'SCCS', 'SVN', 'Arch', 'Bazaar',
1      'Mercurial', and 'Darcs'.
1 
1      As of version 1.30, the following files are excluded:
1 
1         * 'CVS/', and everything under it
1         * 'RCS/', and everything under it
1         * 'SCCS/', and everything under it
1         * '.git/', and everything under it
1         * '.gitignore'
1         * '.gitmodules'
1         * '.gitattributes'
1         * '.cvsignore'
1         * '.svn/', and everything under it
1         * '.arch-ids/', and everything under it
1         * '{arch}/', and everything under it
1         * '=RELEASE-ID'
1         * '=meta-update'
1         * '=update'
1         * '.bzr'
1         * '.bzrignore'
1         * '.bzrtags'
1         * '.hg'
1         * '.hgignore'
1         * '.hgrags'
1         * '_darcs'
1 
1 '--exclude-backups'
1      Exclude backup and lock files.  This option causes exclusion of
1      files that match the following shell globbing patterns:
1 
1      .#*
1      *~
1      #*#
1 
1    When creating an archive, the '--exclude-caches' option family causes
1 'tar' to exclude all directories that contain a "cache directory tag".
1 A cache directory tag is a short file with the well-known name
1 'CACHEDIR.TAG' and having a standard header specified in
1 <http://www.brynosaurus.com/cachedir/spec.html>.  Various applications
1 write cache directory tags into directories they use to hold
1 regenerable, non-precious data, so that such data can be more easily
1 excluded from backups.
1 
1    There are three 'exclude-caches' options, each providing a different
1 exclusion semantics:
1 
1 '--exclude-caches'
1      Do not archive the contents of the directory, but archive the
1      directory itself and the 'CACHEDIR.TAG' file.
1 
1 '--exclude-caches-under'
1      Do not archive the contents of the directory, nor the
1      'CACHEDIR.TAG' file, archive only the directory itself.
1 
1 '--exclude-caches-all'
1      Omit directories containing 'CACHEDIR.TAG' file entirely.
1 
1    Another option family, '--exclude-tag', provides a generalization of
1 this concept.  It takes a single argument, a file name to look for.  Any
1 directory that contains this file will be excluded from the dump.
1 Similarly to 'exclude-caches', there are three options in this option
1 family:
1 
1 '--exclude-tag=FILE'
1      Do not dump the contents of the directory, but dump the directory
1      itself and the FILE.
1 
1 '--exclude-tag-under=FILE'
1      Do not dump the contents of the directory, nor the FILE, archive
1      only the directory itself.
1 
1 '--exclude-tag-all=FILE'
1      Omit directories containing FILE file entirely.
1 
1    Multiple '--exclude-tag*' options can be given.
1 
1    For example, given this directory:
1 
1      $ find dir
1      dir
1      dir/blues
1      dir/jazz
1      dir/folk
1      dir/folk/tagfile
1      dir/folk/sanjuan
1      dir/folk/trote
1 
1    The '--exclude-tag' will produce the following:
1 
1      $ tar -cf archive.tar --exclude-tag=tagfile -v dir
1      dir/
1      dir/blues
1      dir/jazz
1      dir/folk/
1      tar: dir/folk/: contains a cache directory tag tagfile;
1        contents not dumped
1      dir/folk/tagfile
1 
1    Both the 'dir/folk' directory and its tagfile are preserved in the
1 archive, however the rest of files in this directory are not.
1 
1    Now, using the '--exclude-tag-under' option will exclude 'tagfile'
1 from the dump, while still preserving the directory itself, as shown in
1 this example:
1 
1      $ tar -cf archive.tar --exclude-tag-under=tagfile -v dir
1      dir/
1      dir/blues
1      dir/jazz
1      dir/folk/
1      ./tar: dir/folk/: contains a cache directory tag tagfile;
1        contents not dumped
1 
1    Finally, using '--exclude-tag-all' omits the 'dir/folk' directory
1 entirely:
1 
1      $ tar -cf archive.tar --exclude-tag-all=tagfile -v dir
1      dir/
1      dir/blues
1      dir/jazz
1      ./tar: dir/folk/: contains a cache directory tag tagfile;
1        directory not dumped
1 

Menu