cancel
Showing results for 
Search instead for 
Did you mean: 

non-recursive find

SOLVED
Go to solution
wojtek75
Frequent Advisor

non-recursive find

Hi,

I would like to run:
find . -type f -mtime +30 -exec /bin/rm {} \;

only in the current directory without subdirectories. I can't see such an option in find manual of AIX 5.3. Any ideas how I can handle it?
7 REPLIES
smatador
Honored Contributor

Re: non-recursive find

Hi,
Try the option prune
find . -type f -prune -mtime +30 -print
HTH
James R. Ferguson
Acclaimed Contributor
Solution

Re: non-recursive find

Hi:

# cd /path
# find . \( -type f -o -name . -o -prune \) -a -mtime +30 -a -exec ls -ld {} +

If you like the results, change 'ls -ld {} +' to 'rm {} +'.

Using the '+' terminator with '-exec' is much faster since multiple arguments are passed to the spawned process.

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: non-recursive find

> [...] AIX 5.3. [...]

So why ask here?

> Using the '+' terminator [...]

May not work well with the "find" program on
AIX 5.3, but I haven't tried it.

A Forum search for keywords like
find prune
may find more examples. GNU "find" has a
"-maxdepth" option, which may be easier to
use (or understand), and GNU "find" should
be available for AIX.
James R. Ferguson
Acclaimed Contributor

Re: non-recursive find

Hi (again):

I should have written the following to avoid listing subdirectories in the first place:

# find . \( -name . -o -prune \) -type f -mtime +30 -exec ls -ld {} +

I also eliminated the implicit "and" ('-a') for bevity.

Yes, using the '+' terminator works on AIX ( >= 5.2 at least).

Yes, one wishes the HP-UX (and AIX) had the GNU '-maxdepth' option.

And, just maybe the OP has use for this in a script that runs on many flavors of UNIX let alone LINUX...

...JRF...
RC Park
Frequent Advisor

Re: non-recursive find

JRF,

Please explain the use of -o in the syntax,

Thanks...
James R. Ferguson
Acclaimed Contributor

Re: non-recursive find

Hi:

> Please explain the use of -o in the syntax,

The '-o' means "or. An '-a' means "and". see the manpages for 'find()'.

Regards!

...JRF...
RC Park
Frequent Advisor

Re: non-recursive find

JRF,
Yes, thanks! I can see that - In fact, had looked at the man page before posting, but it made no sense reviewing this thread, but for some reason, now it does.

Thanks!

RCP