Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:

...
files/
images/
images/visitors/
...
logs/
...
visitors/

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":

excludeList
files/
visitors/

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:

excludeList
files/
^visitors/

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

1 Answer 1

up vote 1 down vote accepted

Try the --anchored option.

share|improve this answer
    
Worked perfectly. Thanks! This page was helpful: gnu.org/software/tar/manual/html_node/… –  Justin Russell Dec 29 '11 at 20:22

Your Answer

 
discard

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.