cancel
Showing results for 
Search instead for 
Did you mean: 

Script

 
Eric Jacklin
Regular Advisor

Script

Hi

Would you please help me by provide a script which will help me out to
1) Find the file older then 45 days in all the sub directories under a main directory and delete them
2) also capture a log fo ref.
4 REPLIES
Jeeshan
Honored Contributor

Re: Script

>>Find the file older then 45 days in all the sub directories under a main directory and delete them

#find . -type f ! -mtime -45 -exec rm {} \;

>>also capture a log fo ref.

#find . -type f ! -mtime -45 -exec rm {} \; > rm_log.log
a warrior never quits
yulianto piyut
Valued Contributor

Re: Script

for example, you want to delete files older than 45 days in /usr/openv/netbackup/prod_rman_scripts/CTRL

# find /usr/openv/netbackup/prod_rman_scripts/CTRL -mtime +45 -exec rm {}

under main directory:
# find /usr/openv/* -mtime +45 -exec rm {}

thx,

-yut-
likid0
Honored Contributor

Re: Script

With a zsh shell:

#rm */**(.m+45)
Windows?, no thanks
Dennis Handly
Acclaimed Contributor

Re: Script

You should be able to combine ahsan's and yut's solutions:
find path -type f -mtime +45 -print -exec rm -f {} + > rm_log.log