Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-10-2011, 09:14 AM   #1
LQ Newbie
Registered: Apr 2011
Posts: 11

Rep: Reputation: 0
how to exclude multiple directories


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:

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

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!

Old 05-10-2011, 09:28 AM   #2
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
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.
Old 05-11-2011, 03:47 AM   #3
LQ Newbie
Registered: Apr 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Cheers SL00b, but I figured it out using this:

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I exclude multiple directories in awk with find? Damarr Linux - Newbie 11 05-24-2010 02:52 PM
tar exclude directories kais1 Linux - Newbie 1 10-13-2009 09:01 AM
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 12:36 AM
exclude directories from find noir911 Linux - General 3 11-22-2006 06:39 AM
KDAR Q-how to exclude directories... cbjhawks SUSE / openSUSE 1 10-02-2006 04:05 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration