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 trying to perform a full backup of a Linux server using GNU-Tar. The file system looks like this:

├── backup
├── data
│   ├── d1
│   ├── d2
│   └── tmp
│       ├── tt1
│       ├── tt2
│       └── tt3
├── exclude
├── home
│   ├── a
│   ├── b
│   ├── c
│   └── d
├── proc
│   ├── pa
│   ├── pb
│   ├── pc
│   └── pd
├── sys
│   ├── s1
│   ├── s2
│   ├── s3
│   └── s4
└── tmp
    ├── t1
        ├── t2
        └── t3

I'd like to exclude tmp and proc, but preserve /data/tmp/*. However, using the following command:

$tar -X exclude -cvpf -  * | wc -l

with this exclude file:

$cat exclude 

I find that /data/tmp is excluded as well. How can I include data/tmp whilst excluding tmp? More importantly, how should I understand tar's wildcard interpretation and exclude pattern matching. Does every pattern in the exclude file behave like a grep?


share|improve this question
up vote 1 down vote accepted

Try modifying the tar command to tar -X exclude -cvpf - . (ie, change the * to a .) and modifying the exclude file to say


Edit: really? Works for me. Here's my directory structure:

|-- a
| |-- foo
|-- b
| |-- bar
| |-- tmp
| | |-- farr
|-- tmp
| |-- frotz

Here's the contents of my ../exclude file


Then I do tar cvf ../test.tar -X ../exclude . and get


Note that the contents of ./b/tmp are included (./b/tmp/farr is picked up) but those of ./tmp are not (./tmp/frotz is not picked up).

tar is tar (GNU tar) 1.26 on Fedora 16.

share|improve this answer
...doesn't work: data/tmp is still excluded – alpha-lemming Jan 3 '13 at 9:41
interesting effects using the suggested solution: with BSD Tar (on mac), proc, tmp, and data/tmp are excluded. With Gnu-Tar, none of them are excluded. – alpha-lemming Jan 3 '13 at 10:00
My CentOS 6.3 (GNU tar) 1.23 works as expected too. – Iain Jan 3 '13 at 10:53
Ok, thanks, works as expected with Debian and CentOS GNU Tar. Apparently my Mac GNU Tar is messed up. – alpha-lemming Jan 3 '13 at 11:37
@alpha-lemming Your question only mentions GNU tar on Linux. If a Mac is somehow relevant here, it should be in your question. – Michael Hampton Jan 3 '13 at 19:31

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.