Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Command options

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
Hi ,

I am trying to use the find command in a script within a loop like

find ${FILE_DIR} -name $FILE_NAME -mtime +7 -exec gzip {} \;

I am passing the FILE_DIR and FILE_NAME variables.

I need to exclude the files which are already zipped. Is there a way to say {and NOT FILES with an extension of .gz} within the find command.

I dont think -prune can be used here, coz it looks for directories and not individual files.

Many thanx,
 
find ${FILE_DIR} \( -name $FILE_NAME -o ! -name '*.gz' \)-mtime +7 -exec gzip {} \;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops, sorry:

find ${FILE_DIR} \( -name $FILE_NAME \) -o \( ! -name '*.gz' \) -mtime +7 -exec gzip {} \;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hey Thanx that works, except it shld have been a
-a and not -o

Didnt know you cud do that.

Thanx again,
 
Simplest way:
Code:
find $FILE_DIR -name $FILE_NAME ! -name '*.gz' -mtime +7 -exec gzip {} \;


Hope This Help
PH.
 
Well, actually, you don't need to test for it. Gzip won't try to compress a file that's already been gzip'ed. It will just say...
[tt]
$ gzip file.gz
gzip: file.gz already has .gz suffix -- unchanged
[/tt]
So, you'll get some warnings, but you won't be gzipping files that have already been gzipped.

Hope this helps.

 

Hi Sambones,

You are right it will not zip the files, but it still throws up warnings which I wanted to avoid. And I have used the methods mentioned above by PHV and vgersh99.

Thanx to you all for the responses.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top