LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 08-04-2006, 01:25 PM   #1
Harlin
Member
 
Registered: Dec 2004
Location: Atlanta, GA U.S.
Distribution: I play with them all :-)
Posts: 316

Rep: Reputation: 38
How to except a file or package from tarring


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?
 
Old 08-04-2006, 02:35 PM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
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.
 
Old 09-03-2006, 09:52 PM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
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...

Last edited by win32sux; 09-03-2006 at 09:53 PM.
 
Old 09-03-2006, 10:32 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
got it working like this:
Code:
tar cvzf dir1.tar.gz --exclude='dir2' dir1/
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...

Last edited by win32sux; 09-03-2006 at 10:37 PM.
 
Old 09-03-2006, 10:38 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
That's odd, the following works for me. I have a directory called Defaults in my ~/GNUstep directory that I want to exclude from the backup:
Code:
tar -czf /tmp/test.tar.gz --exclude /home/steve/GNUstep/Defaults /home/steve
 
Old 09-03-2006, 10:49 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by gilead
That's odd, the following works for me. I have a directory called Defaults in my ~/GNUstep directory that I want to exclude from the backup:
Code:
tar -czf /tmp/test.tar.gz --exclude /home/steve/GNUstep/Defaults /home/steve
thanks for the reply!!!

i can confirm it doesn't work for me like that... =(

i'm on Ubuntu 6.06 LTS (Dapper Drake)...

maybe i should try on my slackware 10.2 box to see if it makes a difference...
 
Old 09-03-2006, 11:10 PM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
no luck (specifying the dir's path like gilead) on slackware 10.2 either...

Last edited by win32sux; 09-03-2006 at 11:14 PM.
 
Old 09-03-2006, 11:34 PM   #8
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
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...

know any workaround for that??

Last edited by win32sux; 09-03-2006 at 11:36 PM.
 
Old 09-03-2006, 11:42 PM   #9
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
i found a workaround (just specify the current dir):
Code:
tar cvzf dir1.tar.gz --exclude ./dir1/dir2 ./dir1
this way dir2 gets excluded, and the tarball doesn't contain the whole path...

what do you think?? please let me know if theres something wrong with this...

thanks for the help, gilead!!!

Last edited by win32sux; 09-03-2006 at 11:51 PM.
 
Old 09-03-2006, 11:50 PM   #10
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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.

Last edited by gilead; 09-03-2006 at 11:52 PM.
 
Old 09-04-2006, 07:53 AM   #11
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
SOrry, wrong post

Last edited by perfect_circle; 09-04-2006 at 07:55 AM.
 
Old 09-22-2006, 12:10 PM   #12
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
backup of "/" with several dirs excluded:

tar -cvpf image.tar --exclude=/home --exclude=/dev --exclude=/sys --exclude=/proc /
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
un-TARring a bunch of files at once grapnell Linux - General 2 02-12-2006 09:18 AM
un-TARring a bunch of files at once grapnell Linux - Software 4 02-12-2006 09:07 AM
tarring a dd stream john8675309 Linux - Software 1 04-22-2005 03:04 PM
Issue tarring data Johnny Mac Linux - Newbie 5 11-12-2004 02:58 PM
un-tarring multiple files phil1076 Linux - General 19 12-18-2003 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:46 PM.

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