LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   --exclude doesn't work with tar command (https://www.linuxquestions.org/questions/linux-general-1/exclude-doesnt-work-with-tar-command-890290/)

mahmoodn 07-06-2011 01:44 PM

--exclude doesn't work with tar command
 
I don't know why --exclude doesn't work when I use tar command. Please see this code
Code:

mahmood@pc:~$ l a/
1.txt  2.txt  3.txt  b/
mahmood@pc:~$ tar cvjf compressed.tar.bz2 --exclude=/home/mahmood/a/b/ a/
a/
a/2.txt
a/1.txt
a/3.txt
a/b/
mahmood@pc:~$

As you can see although I excluded b/ but tar command ignored that. any idea about that?

colucix 07-06-2011 02:07 PM

In your command the pattern /home/mahmood/a/b/ is not matched by a/b, unless you give the full path to the directory you want to archive:
Code:

tar cvjf compressed.tar.bz2 --exclude=/home/mahmood/a/b /home/mahmood/a
or using the relative path:
Code:

tar cvjf compressed.tar.bz2 --exclude=a/b a
Also notes that the trailing slash at the end of the exclude pattern does not work. I cannot explain exactly this behavior, anyway.

mahmoodn 07-07-2011 01:23 AM

Yes thanks a lot. it works


All times are GMT -5. The time now is 03:40 AM.