Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to tar up a directory. It has a lot(! maybe 1000 or so files) in it's top directory. However it has a subdirectory that I do not want included in the tar archive. How can i tell it to exclude the directory i dont want?
I haven't tried it but maybe something like this may work:
lets say you have the directory dir1 you want to tar and you want to exclude the directory dir2 thats inside dir1: dir1/dir2
Try something like this:
Code:
tar -cvf dir1.tar --exclude=dir1/dir2 dir1
Let me know if it works.
Last edited by perfect_circle; 08-04-2006 at 02:37 PM.
i actually need to do this myself, but i'm still trying to figure it out... i can confirm that your illustration unfortunately doesn't work here... i've tried all these:
Code:
tar cvzf dir1.tar.gz --exclude=dir1/dir2/ dir1/
Code:
tar cvzf dir1.tar.gz --exclude=./dir1/dir2/ dir1/
Code:
tar cvzf dir1.tar.gz --exclude=/path/to/dir1/dir2/ dir1/
and no luck with any of them... i suspect it's a syntax problem, not sure... when/if i figure it out i'll post, but if you or anyone else knows what i'm doing wrong your input would be greatly appreciated...
but this is gonna make it ignore ANY subdirectory (or file) named "dir2", right??
that would suck... =/
i'd like to make it so that only the specified directory (and no others, even if they have the same name) is excluded... my guess is the path would need to be specified, but i can't get it to work like that yet...
seems like i couldn't get the exclusion to work with gilead's example because (unlike him) i wasn't specifying the entire path for the directory to be tarballed... in other words, it won't work for me like this:
Code:
tar cvzf dir1.tar.gz --exclude /tmp/dir1/dir2 dir1
but it DOES work for me like this:
Code:
tar cvzf dir1.tar.gz --exclude /tmp/dir1/dir2 /tmp/dir1
the only thing that kinda sucks is that doing it like this makes the entire path be put into the tarball... so whenever someone untars the file they will end-up with a "tmp" directory which they will have to CD into to get to dir1... imagine if it was a much more complex path...
hmmm - I was starting to doubt myself so I ran it again. Thankfully it worked again:
Code:
$ ls -l /home/steve/GNUstep
total 8
drwxr-x--- 2 steve steve 4096 2006-07-13 09:45 Defaults/
drwxr-x--- 4 steve steve 4096 2006-02-28 11:15 Library/
$ pwd
/tmp/tar-test
$ tar -czf /tmp/tar-test/test.tar.gz --exclude /home/steve/GNUstep/Defaults /home/steve
tar: Removing leading `/' from member names
$ tar -zxf test.tar.gz
$ ls -l home/steve/GNUstep
total 4
drwxr-x--- 4 steve steve 4096 2006-02-28 11:15 Library/
Most times I'm running tar from the directory (or the parent) of the sources anyway so your workaround would work here as well.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.