1834513 Members
2072 Online
110068 Solutions
New Discussion

Re: Delete Script

 
Prabhu_7
Frequent Advisor

Delete Script

I'm looking for a script , which deletes all files those are modified 2 months back and prior to that.

find /backup_files -name 'branch_file*' -type f -xdev -mtime +60 -exec rm {} \;

This removes only files that are modified between 1416 hours(59th day) and 1440 hours (60th days) back.
But i also want to delete files that was accessed 2 yrs back. So i need a generalized
script which deletes all files older(modified) than 2 months.

Thanks
4 REPLIES 4
Paula J Frazer-Campbell
Honored Contributor

Re: Delete Script

HI

This post covers what you require:-



http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x5a4135a43b46d71190080090279cd0f9,00.html


Paula
If you can spell SysAdmin then you is one - anon
Steven E. Protter
Exalted Contributor

Re: Delete Script

Script is attached.

It only works with cron, ie no terminal. You will have to hack it to make it work with a TERM session. Its not hard though.

It uses a configuration file that lets you limit what directories it can touch. Just include the folder or filesystem name.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Delete Script

Script is attached.

It only works with cron, ie no terminal. You will have to hack it to make it work with a TERM session. Its not hard though.

It uses a configuration file that lets you limit what directories it can touch. Just include the folder or filesystem name.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Delete Script

Hi Prabhu:

You might try this modification:

# find /backup_files -xdev \( -type f -a -name "branch_file*" -a -mtime +60 \) -exec rm {} \;

Note that spaces follow the open parentheses and precede the close parentheses. Note, too, that the parentheses must be escaped.

Regards!

...JRF...