Why does the command tar -cvpzf backup_140128.tar.gz --exclude=/backup_140128.tar.gz --exclude=/temp_intel * not exclude the /temp_intel directory?

  • Because the * is expanded by the shell before tar can see it. Try tar -cvpzf backup_140128.tar.gz --exclude=/backup_140128.tar.gz --exclude=/temp_intel\* (notice the backslash).
    – Rmano
    Jan 28, 2015 at 17:51
  • There's a space before the * so I don't think this is the problem :/
    – roadmr
    Jan 28, 2015 at 18:02

1 Answer 1


If you're running this from /, the * will list directories without the leading slash. Try it yourself; do for dir in *; do echo $dir; done.

This is exactly what tar will see, and clearly temp_intel doesn't match the /temp_intel expression given to --exclude. Actually, I rather suspect backup_140128.tar.gz, if present, is also not being excluded.

So three options (I haven't tried any of them, this is theoretical):

  1. Force addition of the slash by using /* in your tar command line.
  2. Use --exclude=temp_intel so it matches (assuming you don't have any other temp_intel directories you want excluded).
  3. Play with the --anchored option to tar, the description wasn't very clear but I think it may remove the leading / before doing the comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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