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 and -prune don't behave as expected 2

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Hi Guys
I have a simple find command on AIX 4.3.3 :
find /sybase/applications/sda/outputs -name "CMGS*[0-9]" -mtime 1 -print -prune

but it also picks up all matching files in my sub-directory 'savold' ( 2-day old files saved away )
Which I don't want to catch in the find command!
I thought -prune would prevent this - I also tried
find . -name "CMGS*[0-9]" -mtime 1 -print -prune
and
find . -name "/sybase/applications/sda/outputs/CMGS*[0-9]" -mtime 1 -print -prune

and still catch the old saved files in dir savold.
Anybody care to enlighten me ?
Cheers ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Ooops - didn't point out that files in savold directory could be less than 24 hours old ( if previous run was late in executing) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Yep. You need to use:
Code:
find . \( -type d ! -name . -prune \) -o \( -type f -name CMGS*[0-9]" -mtime 1 -print \)
Cheers, Neil
 
Thanks Neil - That worked well ( when I put the missing " after -name )
If I have (less that 24 hours old) files from yesterday's run ( which I want to ignore ) still in my sybase/applications/sda/outputs directory, is there any method of using -mtime or -atime to ignore them ? ( by hours rather than days, for example )
Thanks

Dickie Bird
db@dickiebird.freeserve.co.uk
 
The easiest way to do this is to create an empty 'timestamp' file either via cron or the script creating the output files, like:
Code:
touch timestamp
Then when you want to find files older than this timestamp, use:
Code:
find . \( -type d ! -name . -prune \) -o \( -type f ! -newer timestamp -print \)
Cheers, Neil :)
 
An if I create the timestamp file first, I can find files created after this timestamp, using:

find . \( -type d ! -name . -prune \) -o \( -name "CSG*" -type f -newer timestamp -print \)

Brill !
TAL [wavey]

Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top