LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-23-2006, 10:08 PM   #1
LocoMojo
Member
 
Registered: Oct 2004
Distribution: Slackware 12
Posts: 165

Rep: Reputation: 30
Excluding directories from tar?


I wrote up a simple backup script and it works great, except there's a few directories in my /home directory that I want to exclude from backups as I've already backed them up separately. I read the tar manuals, but I can't seem to get the syntax right. According to man tar I have the "--exclude File" option, does this mean I can only exclude individual files and not directories?

To be specific, I'm trying to exclude the build (kernel source), pictures, and music directories which together weigh almost 4G. If it is at all possible to exclude these directories from being archived, what is the exact syntax to archive my /home directory sans the abovementioned directories?

Thanks in advance for any help.

LocoMojo
 
Old 01-23-2006, 10:23 PM   #2
kvedaa
Member
 
Registered: Mar 2004
Location: Virginia
Distribution: PacketProtector
Posts: 331

Rep: Reputation: 30
Depending in the version that you are using you might have the ablity to use the following option:

--exclude-from file Exclude files listed in file.

thus you would create a file that you would list those files that you would not want to be joined to the tar that you are creating. I would check the man page for tar on your version to see if it is supported, or if you are bolder, you could take it for a spin.

Good luck,
 
Old 01-23-2006, 10:53 PM   #3
LocoMojo
Member
 
Registered: Oct 2004
Distribution: Slackware 12
Posts: 165

Original Poster
Rep: Reputation: 30
Hi kvedaa,

Thanks for your reply.

Ahh, that makes sense. So "File" refers to a file which lists the directories to be excluded.

Ok I just gave it a go with a small directory (100mb) containing 8 subdirectories. I'm still not getting the syntax right so I'm getting errors.

I was trying to create a tar.gz of /home/LocoMojo/documents. Normally I would issue the command "tar czvf documents.tar.gz ~/documents", but now I'm trying to exclude the ~/documents/web, ~/documents/manuals, and ~/documents/work directories so I wrote up a file called "excludes" like this:

Quote:
~/documents/manuals
~/documents/web
~/documents/work
But it still didn't work. I tried issuing the command several different ways.

Quote:
tar -czvf documents.tar.gz ~/documents -X ~/excludes
tar -czvfX ~/excludes documents.tar.gz ~/documents
tar -X ~/excludes -czvf documents.tar.gz ~/documents
tar -czvf documents.tar.gz ~/documents -X=~/excludes
...and a couple of others, but none of them work.

What is the exact syntax?

LocoMojo
 
Old 01-23-2006, 11:41 PM   #4
LocoMojo
Member
 
Registered: Oct 2004
Distribution: Slackware 12
Posts: 165

Original Poster
Rep: Reputation: 30
Update:

I couldn't get it to work with a file, but I found a way to make it work. It's pretty ugly, but it works:

Quote:
tar czvf documents.tar.gz --exclude='*/manuals/*' --exclude='*/web/*' --exclude='*/work/*' ~/documents
I couldn't get it to work with --exclude='*/manuals/*,*/web/*,*/work/*' though. That would be a little less ugly.

Anyone out there know a more elegant way of doing this?

LocoMojo
 
Old 01-24-2006, 12:27 AM   #5
jib2
Member
 
Registered: Sep 2003
Location: Paris, France
Distribution: Arch x86_64
Posts: 221

Rep: Reputation: 30
The syntax is tar <options..> <files_to_tar..>

tar -czf documents.tar.gz --exclude-from your_exclude_file ~/documents
 
Old 01-24-2006, 12:55 AM   #6
LocoMojo
Member
 
Registered: Oct 2004
Distribution: Slackware 12
Posts: 165

Original Poster
Rep: Reputation: 30
Hi jib2,

I did exactly that, but it still isn't working.

How are you supposed to format your exclude file?

Thanks.

LocoMojo
 
Old 01-24-2006, 01:01 AM   #7
LocoMojo
Member
 
Registered: Oct 2004
Distribution: Slackware 12
Posts: 165

Original Poster
Rep: Reputation: 30
Never mind, I got it.

Whew!

Thanks

LocoMojo
 
  


Reply


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
excluding directories from commands David the H. Linux - General 5 04-06-2009 03:21 PM
excluding hidden directories when using tar djgerbavore Slackware 3 01-05-2006 03:49 PM
Find excluding multiple directories with a wildcard pteigeler Linux - Software 1 09-02-2005 10:57 AM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 12:32 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM


All times are GMT -5. The time now is 01:04 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration