Why does the command tar -cvpzf backup_140128.tar.gz --exclude=/backup_140128.tar.gz --exclude=/temp_intel *
not exclude the /temp_intel
directory?
1 Answer
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):
- Force addition of the slash by using
/*
in your tar command line. - Use
--exclude=temp_intel
so it matches (assuming you don't have any othertemp_intel
directories you want excluded). - 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.
*
is expanded by the shell beforetar
can see it. Trytar -cvpzf backup_140128.tar.gz --exclude=/backup_140128.tar.gz --exclude=/temp_intel\*
(notice the backslash).*
so I don't think this is the problem :/