nir_s
April 27, 2008, 4:22am
1
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
ripat
April 27, 2008, 4:32am
2
Hi,
Use -maxdepth 1 option for the find command.
nir_s
April 27, 2008, 9:24am
3
Hi,
I didn't find such an option in "find" command..
Can you post an example?
Thanks in advance,
Nir
era
April 27, 2008, 9:49am
4
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=.)
nir_s
April 27, 2008, 10:43am
6
Thanks guys!
Finally, I used "find . \( ! -name . -prune \)" and it works perfect!
Best regards,
Nir