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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Find without searching subdirectories

Status
Not open for further replies.

bosoxer1

Programmer
Jan 22, 2005
20
0
0
US
I am trying to search for all files with "*20*" in the file name, but this command keep searching subdirectories.

I need to search only at the current level.

find . -name "*.20*" -mtime +10;

I have tried -prune, -depth, but still no luck.

Any thoughts?
 
-maxdepth is not supported in AIX 5.2. Any other thoughts?
 
Some flavors of find have a -level primary.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Stirke two....-level is not supported...

I'm a bit closer with.... find . -type f -name "*.20*" -mtime +10 -o -type d -name archive -prune -exec rm {} \;

it bypasses the files in the sub dir archive(GOOD), but does list archive dir, and tries to delete entire dir(BAD).
 
how about:

find . -prune -type f -name "*.20*" -mtime +10 -print

(not at an AIX box right now, so can't verify it myself, not sure if I read the man page correctly)

change '-print' to '-exec rm {} \;' if satisfied with result.

HTH,

p5wizard
 
No luck.....the prune up front stops all files from being listed.

I think I have to do this in multiple steps, find the files, awk the output to remove directories, and then pipe the results to a rm command.

Not sure if that can be done, buy will try...
 
bosoxer1 said:
No luck.....the prune up front stops all files from being listed.
I figured that out by now also. :-(

well then...

find . -type f -name '*.20*' -mtime +10 -print|grep -v /|xargs rm


HTH,

p5wizard
 
make that

find . -type f -name '*.20*' -mtime +10 -print|grep -v "/.*/"|xargs rm

or from olded's link:

find . \( -type d ! -name . -prune \) -o \( -type f -name '*.20*' -mtime +10 -print \)

find . \( -type d ! -name . -prune \) -o \( -type f -name '*.20*' -mtime +10 -exec rm {} \; \)



HTH,

p5wizard
 
And shorter; no need for brackets or test for dir (which is inherent to -prune):

find . ! -name . -prune -type f -name '*.20*' -mtime +10


HTH,

p5wizard
 
Thank you guys....You came through again....
 
Maybe I'm being dumb, and I wouldn't take away from all the gurus who know all the find options, but, if you want all the files in one directory which have the name "*.20*" what's wrong with
Code:
ls *.20*
and, simpler still, if you want to itterate through them rather than just list them
Code:
for file in *.20*
do
   process $file
done

Ceci n'est pas une signature
Columb Healy
 
Columb,

Would you not get "argument list too long" while using
Code:
ls *.20*
if there were too many files?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top