Server Fault is a question and answer site for system and network administrators. 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'm working on doing a pretty straightforward tar for a site, but there's a wrinkle. Here's the file structure of the site:


Here's the problem: I want to exclude all the files in the main visitors/ directory, but I want all the files in the images/visitors/ directory to be included in the tarball.

I've been trying tar c --exclude-from='excludeList' with the following as the content of "excludeList":


Unfortunately, since the files in images/visitors/ match the visitors/ pattern, they're excluded, too. In a perfect world, I could go regex with something like this:


But that doesn't work. Is there any way to make this work, either straight through tar or with another sort of pattern-matching command?

share|improve this question
up vote 1 down vote accepted

Try the --anchored option.

share|improve this answer
Worked perfectly. Thanks! This page was helpful:… – Justin Russell Dec 29 '11 at 20:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.