LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-11-2010, 02:03 AM   #1
infraquest
LQ Newbie
 
Registered: Jun 2010
Posts: 4

Rep: Reputation: 0
tar excluding some files


I am working on a backup script and have to use tar with --exclude option somewhere in the script.

scenario:
I need create a single tar ball with contents of two directories test1 and test2. In directory test1, all .jpg files needs to be excluded, but all the contents of another directory test2 (including .jpg files) has to be taken while tarring.

A command like following excludes .jpg files in both test1 and test2 directories, but I need to exclude .jpg files only from /home/test2.

tar -hcvzf testing.tar.gz /home/test1 --exclude *.jpg /home/test2

It would be great if someone could give some ideas.

Thanks,
Shan
 
Old 06-11-2010, 02:35 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Untested:

tar -hcvzf testing.tar.gz /home/test1 /home/test2 --exclude /home/test2/*.jpg

Hope this helps.
 
Old 06-11-2010, 04:25 AM   #3
infraquest
LQ Newbie
 
Registered: Jun 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Hi druuna,

That works! never thought of giving full path .
Thanks many
 
Old 06-11-2010, 04:26 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome

Could you mark this as solved (see thread tools).
 
Old 06-11-2010, 05:33 AM   #5
infraquest
LQ Newbie
 
Registered: Jun 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Hi again druuna,

I need one more help here.

>> tar -hcvzf testing.tar.gz /home/test1 /home/test2 --exclude /home/test2/*.jpg

Command excludes all jpg files in the location /home/test2/, but I need all jpg files in sub directories under /home/test2/ to be excluded as well. how can I go about this?

Thanks
 
Old 06-11-2010, 06:01 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Have a look at the -X (or --exclude-from=file) option (GNU Tar : 6.4 Excluding Some Files)

All exclusions should be in a file (could be filled by using find, might need some editing).

Hope this helps.
 
1 members found this post helpful.
Old 06-11-2010, 06:22 AM   #7
infraquest
LQ Newbie
 
Registered: Jun 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks druuna,
yes I used --exclude-from option to exclude the jpg files recursively and got around this.
I'll close the thread.

Regards,
 
Old 06-11-2010, 06:35 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
excluding files and 'mv' surfbass Linux - General 3 07-15-2006 07:59 PM
Excluding directories from tar? LocoMojo Linux - Software 6 01-24-2006 01:01 AM
excluding hidden directories when using tar djgerbavore Slackware 3 01-05-2006 03:49 PM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 12:32 PM
tar and excluding files murshed Linux - Newbie 7 03-15-2003 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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