To avoid operating on files whose names match a particular pattern,
use the --exclude or --exclude-from options.
--exclude=pattern
Causes tar to ignore files that match the pattern.
The --exclude=pattern option prevents any file or member whose name
matches the shell wildcard (pattern) from being operated on.
For example, to create an archive with all the contents of the directory
src except for files whose names end in .o, use the
command ‘tar -cf src.tar --exclude='*.o' src’.
You may give multiple --exclude options.
--exclude-from=file
-X file
Causes tar to ignore files that match the patterns listed in
file.
Use the --exclude-from option to read a
list of patterns, one per line, from file; tar will
ignore files matching those patterns. Thus if tar is
called as ‘tar -c -X foo .’ and the file foo contains a
single line *.o, no files whose names end in .o will be
added to the archive.
--exclude-caches
Causes tar to ignore directories containing a cache directory tag.
When creating an archive, the --exclude-caches option causes
tar to exclude all directories that contain a cache
directory tag. A cache directory tag is a short file with the
well-known name CACHEDIR.TAG and having a standard header
specified in https://www.brynosaurus.com/cachedir/spec.html.
Various applications write cache directory tags into directories they
use to hold regenerable, non-precious data, so that such data can be
more easily excluded from backups.