How to tar this dir excluding some files .au? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to tar this dir excluding some files .au?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-04-2013
manalisharmabe manalisharmabe is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 13 June 2014, 4:26 AM EDT
Posts: 159
Thanks: 103
Thanked 2 Times in 2 Posts
RedHat How to tar this dir excluding some files .au?

Hi all,

Thanks for previous help.
How to include this in script,
I need to tar files which are present in /var/spool/cron/crontabs directory (used for crontab) excluding those files which are having extension .au

Code:
/var/spool/cron/crontabs>>ls -ltr | grep -v .au
total 438
-rw-------   1 root     root          16 Oct 19  2008 batch010
-rw-------   1 root     root          58 Oct 19  2008 batch451
-rw-------   1 root     root         752 Oct 19  2008 lp
-rw-------   1 root     root         287 Oct 19  2008 sys
-rw-r--r--   1 root     root           1 Feb 11  2009 root
-rw-------   1 root     qad         2217 Apr  2  2010 batch471
-rw-------   1 root     qad          462 Apr 18  2010 ibi

Please advice,
I guess this might work: -

Code:
find /var/spool/cron/crontabs -grep -v .au -exec tar cvf {} \;

But I need to put this in the script:-

Last edited by Scrutinizer; 02-04-2013 at 05:37 AM.. Reason: code tags
Sponsored Links
    #2  
Old 02-04-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 21 July 2014, 11:56 PM EDT
Location: India
Posts: 1,816
Thanks: 24
Thanked 519 Times in 498 Posts

Code:
find /var/spool/cron/crontabs -not -name "*.au" -exec tar cvf myArchive.tar {} \;

The Following User Says Thank You to balajesuri For This Useful Post:
manalisharmabe (02-04-2013)
Sponsored Links
    #3  
Old 02-04-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 25 July 2014, 12:44 PM EDT
Location: Aachen, Germany
Posts: 3,886
Thanks: 62
Thanked 922 Times in 875 Posts
Had you a recent bash, you could use extended globbing:
Code:
$ shopt -s extglob
$ tar cf myArch.tar  /var/spool/cron/crontabs/!(*.au)

The Following User Says Thank You to RudiC For This Useful Post:
manalisharmabe (02-04-2013)
    #4  
Old 02-04-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 25 July 2014, 1:14 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,119
Thanks: 43
Thanked 769 Times in 605 Posts
Quote:
Originally Posted by balajesuri View Post
Code:
find /var/spool/cron/crontabs -not -name "*.au" -exec tar cvf myArchive.tar {} \;

I don't think this will work at all, because the "-exec" clause of find executes the command for every file found by "find" separately. This means, the first file found will execute


Code:
tar cvf myarchive.tar 1st.file

and the second file found will trigger execution of


Code:
tar cvf myarchive.tar 2nd.file

and so on. Because of the "c"-option in tar every time a new file is found it will create "myarchive.tar" anew, overwriting the previous one. To go with this method one would have to create the tar archive previously and then add to it:


Code:
tar cvf myArchive.tar
find /var/spool/cron/crontabs -not -name "*.au" -exec tar Af myArchive.tar {} \;

But it would probably be easier to feed "tar" the list of file names via <stdin>:


Code:
find /var/spool/cron/crontabs -not -name "*.au" -print | tar -cf myArchive.tar

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
manalisharmabe (02-04-2013)
Sponsored Links
    #5  
Old 02-04-2013
manalisharmabe manalisharmabe is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 13 June 2014, 4:26 AM EDT
Posts: 159
Thanks: 103
Thanked 2 Times in 2 Posts
Thanks Guys for reply,

I will soon post what I did to get this done.
Sponsored Links
    #6  
Old 02-05-2013
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 July 2014, 9:39 AM EDT
Posts: 2,741
Thanks: 103
Thanked 848 Times in 799 Posts
As your on redhat you probably have GNU tar so you could use the --exclude option:


Code:
tar cvf myArchive.tar --exclude='*.au' /var/spool/cron/crontabs

Sponsored Links
    #7  
Old 02-05-2013
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by bakunin View Post
But it would probably be easier to feed "tar" the list of file names via <stdin>:


Code:
find /var/spool/cron/crontabs -not -name "*.au" -print | tar -cf myArchive.tar

I don't think any tar implementations read filenames from stdin. Perhaps you're thinking of the wonderful pax utility.

Regards,
Alister
The Following User Says Thank You to alister For This Useful Post:
vbe (02-06-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
List files older that 7 days in a dir, excluding all subdirs jwbijl UNIX for Dummies Questions & Answers 6 06-04-2012 09:38 AM
Excluding file from tar chriss_58 Shell Programming and Scripting 3 11-17-2010 07:28 AM
Excluding a file from tar... lwif UNIX for Advanced & Expert Users 2 05-11-2010 09:23 AM
help writing rm script excluding specific titled dir nomados Shell Programming and Scripting 1 01-15-2010 07:30 PM
Excluding files using tar cXzf sampipe UNIX for Dummies Questions & Answers 11 07-28-2005 09:46 AM



All times are GMT -4. The time now is 02:16 PM.