How to remove old files without recursion?

Hi folks,

I need to write a script which remove files with suffix *.dmp from a specific directory ,older than 30 days and not including recursive subdirectories.

I.e:
The following command remove recursive all *.dmp files older than 30 days:

find $ORACLE_BASE -mtime +30 -type f -name "*.dmp" -exec rm {} \; 

I need to remove files older than 30 days but only under $ORACLE_BASE without its subdirectories.

How to do it?

Thanks in advance,
Nir

Hi,

Use -maxdepth 1 option for the find command.

Hi,

I didn't find such an option in "find" command..
Can you post an example?

Thanks in advance,
Nir

If your find doesn't have that option, an example will hardly help?

find $ORACLE_BASE -maxdepth 1 -mtime +30 -type f -name "*.dmp" -exec rm {} \;

You can filter the output from find to exclude anything with at least two slashes in it, though:

find $ORACLE_BASE -mtime +30 -type f -name "*.dmp" -print |
grep -v '/.*/' | xargs -r rm

You might want to try it with "xargs echo rm" for testing.

The number of slashes obviously depends on the number of slashes in $ORACLE_BASE -- two would be correct for the current directory. (ORACLE_BASE=.)

Or this might help you:

Thanks guys!

Finally, I used "find . \( ! -name . -prune \)" and it works perfect!

Best regards,
Nir