How to tar this dir excluding some files .au?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tar this dir excluding some files .au?
# 1  
Old 02-04-2013
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
/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: -
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 07:37 AM.. Reason: code tags
# 2  
Old 02-04-2013
find /var/spool/cron/crontabs -not -name "*.au" -exec tar cvf myArchive.tar {} \;

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-04-2013
Had you a recent bash, you could use extended globbing:
$ shopt -s extglob
$ tar cf myArch.tar  /var/spool/cron/crontabs/!(*.au)

This User Gave Thanks to RudiC For This Post:
# 4  
Old 02-04-2013
Originally Posted by balajesuri
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

tar cvf myarchive.tar 1st.file

and the second file found will trigger execution of

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:

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>:

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

I hope this helps.

This User Gave Thanks to bakunin For This Post:
# 5  
Old 02-04-2013
Thanks Guys for reply,

I will soon post what I did to get this done.
# 6  
Old 02-05-2013
As your on redhat you probably have GNU tar so you could use the --exclude option:

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

# 7  
Old 02-06-2013
Originally Posted by bakunin
But it would probably be easier to feed "tar" the list of file names via <stdin>:

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.

This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Excluding directory in my tar Backup

Hello AIX experts. Hope this topic finds you well :) Now, I will take a backup for a directory called medcbs. Inside this directory 1 subdirectory I don't want to include it in the backup. So, how to exclude it? To be more clear, take a look to the following: /bossapp1/medcbs>... (4 Replies)
Discussion started by: Mohannad
4 Replies

2. UNIX for Dummies Questions & Answers

List files older that 7 days in a dir, excluding all subdirs

Hi, I would like to list all files, older than 7 days, in a directory, but exclude all subdirectories in the find command. If I use find . -type f -mtime +7 all files in the subdirs are also included. How can I exclude them? Regards, JW (6 Replies)
Discussion started by: jwbijl
6 Replies

3. Shell Programming and Scripting

Excluding file from tar

Hello i am using HP-UX rapdb2 B.11.23 U ia64 1068321383 unlimited-user license. I am tryiyng to exclude for tar all files that start with TOT* but i doues not work I am using: tar -cvf /ODS/prepaid/CDR_FLOW/WORK/backup.tar --exclude='TOT*' and i get the error: tar: cannot stat... (3 Replies)
Discussion started by: chriss_58
3 Replies

4. UNIX for Advanced & Expert Users

Excluding a file from tar...

The title is not as easy as it sounds.... I am trying to exclude and file while ssh and untaring the file on the fly. The command I am using is... The command typically works but recently I've add the X option along with the exclude file. Essentially, the exclude file is being ignored when run... (2 Replies)
Discussion started by: lwif
2 Replies

5. Shell Programming and Scripting

help writing rm script excluding specific titled dir

I am attempting to write a housecleaning script that does the following: 1) goes to a specific directory 2) deletes all contents of that directory but a specific directory within it. So my users all keep and use the Shared directory in OSX. Within /Users/Shared there are also standard named... (1 Reply)
Discussion started by: nomados
1 Replies

6. Shell Programming and Scripting

Creating tar excluding links

hi, How do i create a tar file of a directory excluding the links in that particular directory and its sub-directories. The below command doesnt work for me. tar -cvf abc.tar /dir1 --exclude"^l" (1 Reply)
Discussion started by: yesmani
1 Replies

7. Shell Programming and Scripting

excluding directories in tar

In a bash script I am writing I am having a problem excluding selected directories from tar. From the machine $SERVER I issue the command #start netcat on storage server gnetcat -l -vv -p 2011 >$FILEPATH/$SHORT_NAME.$today.tar & The the following command is then sent to the $CLIENT. #start... (2 Replies)
Discussion started by: thumper
2 Replies

8. UNIX for Dummies Questions & Answers

Excluding files using tar cXzf

Hi All, I'm having trouble with creating a compressed tar file with tar cXzfv and even with normal cvXf I created a simple test below.. can anyone spot the mistake I'm making??.. its driving me up the wall.. In the end I need a compressed tarball.... Thanks in advance!! Sam ... (11 Replies)
Discussion started by: sampipe
11 Replies

9. UNIX Desktop Questions & Answers

tar backup with excluding some folders

Hi , I want to backup the root file system but the size of / is very huge so I want to exclude some file systems.Man page of tar says X option excludes files but I could not do that.I use this command $ tar -cvf deneme.tar -X exc . $ cat exc sql kkm I think there... (2 Replies)
Discussion started by: kudret_gulcan
2 Replies

10. UNIX for Dummies Questions & Answers

excluding directories while using tar

How do I exclude some directories while creating a tar file with a number of directories? thanks. (2 Replies)
Discussion started by: uchachra
2 Replies
Login or Register to Ask a Question

Featured Tech Videos