1844310 Members
3444 Online
110230 Solutions
New Discussion

HP-UX shell script

 
Roro_2
Regular Advisor

HP-UX shell script

Hi,

I need help in order to create a shell script which delete contineiusly files created one year ago.
means that one the file should be deleted once its creation date exceeds one year

Thanks and Regards

Joe
3 REPLIES 3
Ivan Krastev
Honored Contributor

Re: HP-UX shell script

Pete Randall
Outstanding Contributor

Re: HP-UX shell script

Joe,

First you need to be aware that Unix has no method of tracking creation time - the time stamp on a file is the last modified time.

Given that, you can use a simple find command to accomplish your goal:

find /start-dir -type f -mtime +365 -exec rm {} \;

- or -

find /start-dir -type f -mtime +365 |xargs rm

The second method is a bit more efficient since the first spawns a separate process for each removal.


Pete

Pete
Dennis Handly
Acclaimed Contributor

Re: HP-UX shell script

>Pete: The second method is a bit more efficient

Change the first to:
find /start-dir -type f -mtime +365 -exec rm +