Operating System - HP-UX
1833988 Members
1689 Online
110063 Solutions
New Discussion

Re: Find - Only apply to current directory

 
Radhe Webster
Occasional Advisor

Find - Only apply to current directory

I need to search for files that are older than a certain amount and then delete them. How do I prevent find from going into subdirectories and deleting those that match the criteria as well.

Thanks
6 REPLIES 6
Wilfred Chau_1
Respected Contributor

Re: Find - Only apply to current directory

try the -prune flag to skip the subdirectories.
Alan Meyer_4
Respected Contributor

Re: Find - Only apply to current directory


the -prune switch prevents the find command from travelling down directory trees
" I may not be certified, but I am certifiable... "
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Find - Only apply to current directory

Combine the -purne flag with -type d

So you will scan only the current directory and not the child ones.
Vibhor Kumar Agarwal
Muthukumar_5
Honored Contributor

Re: Find - Only apply to current directory

You can do it like,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=45258

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Find - Only apply to current directory

If you want to delete files based on modified time then,

find -path "//*" -prune -type f -mtine +2 -exec rm -i {} \;

hth.
Easy to suggest when don't know about the problem!
Radhe Webster
Occasional Advisor

Re: Find - Only apply to current directory

Thanks for all the help.