Operating System - HP-UX
1752653 Members
5828 Online
108788 Solutions
New Discussion

Re: Find command to delete files in dir

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor
Solution

Re: Find command to delete files in dir

>if I want to exclude particular directory then what will be the syntax:

Is that directory name unique and do you want to exclude subdirectories too?
find /startdir -name exclude-dir -prune -o -type f -mtime +180 -exec echo rm {} +

Anything in exclude-dir or deeper would be skipped. Remove "echo" after you verified it works.

If that directory wasn't unique, you would need to use -path.

>Pete: find /startdir -type f -mtime +180 |xargs rm

Using "-exec ... +" would be much faster:
find /startdir -type f -mtime +180 -exec rm {} +

I recently had to remove 100,000 messages out of /var/spool/mqueue/ and "-exec ... +" was much faster than xargs. And I was using -n1000.
HP-UX_Ali
Regular Advisor

Re: Find command to delete files in dir

I have found the solution & hence closing the thread.