LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to exclude multiple directories (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-exclude-multiple-directories-879823/)

amario26 05-10-2011 09:14 AM

how to exclude multiple directories
 
Hi,

I am trying to exclude multiple directories when using tar. I can do it for just one directory with --exclude=directory

I can also do it for multiple directories by typing that code again and again. But.. I now have this:

Code:

tar -czpv --exclude="$EXCLUDE"
where the $EXCLUDE is a variable that looks like this:

Code:

EXCLUDE=".gnome2 excludingtest'
As you can see im trying to call this variable that has endless amounts of directories in it seperated by a space.. but when run it doesnt work! It will however work if i just put one directory in the variable. Any ideas?

Many thanks!

Also.. i tried --exclude-tag --exclude-tag-all --exclude-tag-under but to no avail.

Any help would be greatly appreciated!

Thanks

SL00b 05-10-2011 09:28 AM

The tar exclude statement is not in the form --exclude=directory, it's in the form --exclude PATTERN. If there was a common naming pattern to the directories you wanted to exclude, (dir01, dir02, etc.), then that's the way you would accomplish that.

You can also use the --exclude-from FILE parameter, where the named file contains a list of files to be excluded. I'm not sure if it could be used to just specify directories instead, but it might be worth a shot.

Another method would be to run multiple tar commands for each directory you actually want to back up, and append them all to the file created in the first one.

amario26 05-11-2011 03:47 AM

Cheers SL00b, but I figured it out using this:

Code:

-X <(for i in ${EXCLUDE}; do echo $i; done)


All times are GMT -5. The time now is 04:54 AM.