Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to exclude some directories from backup. But not all with specific name - only those lying under specified root directory. With rsync I would use exclude mask like this:

/path/excludeRoot/**/directoryToExclude

which means that all directories with name directoryToExclude lying below /path/excludeRoot will be excluded.

On the other hand: each directory with name directoryToExclude but lying elsewhere will be included

Is it possible to do it with tar?

share|improve this question

That is, unfortunately not straightforwardly possible as the --exclude family of options is not powerful enough.

One approach would be to obtain the list of objects using external program (say find) and then use -T switch to tell tar which files/objects should be included.

Quoting from the man page:

-T, --files-from FILE
  get names to extract or create from FILE

If the filenames contain special symbols (and/or spaces) I would add --null to the tar command line; to generate the list I would also use -print0 with find -- to separate the files/dirs with NUL (\000) character.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .