Operating System - HP-UX
1755703 Members
3971 Online
108837 Solutions
New Discussion юеВ

Scripting deleting files older than XX number of days

 
SOLVED
Go to solution
Chad Brindley
Regular Advisor

Scripting deleting files older than XX number of days

Hello all
Every day we FTP a lot of files to and from legacy systems. What I would like to know (and how to do it) is that is it possible to write a simple script to check a certain file system path for any files that are 90 days or older and delete them. (Instead of me manually removing them each month)
of course I don't want to search the whole system. These files are held in their own file system;
/interface//archive
(there are several interfaces and we would have to look at each one.

We would put this script in the cron.

many thanks
Chad.
7 REPLIES 7
Robert-Jan Goossens_1
Honored Contributor

Re: Scripting deleting files older than XX number of days

Hi Chad,

# find /filesystem -mtime +90 -type f -exec ll {} \;

try above command to list files older then 90 days, if it works change the ll into rm. You clould also add this command into a script.

Hope this helps,
Robert-Jan
VEL_1
Valued Contributor

Re: Scripting deleting files older than XX number of days


Use the find command in cron to remove old log files:

The following command will delete the files which are not accessible for last 90 days.

find /interface//archive -type f -atime +90 -exec rm -rf {} \;
MarkSyder
Honored Contributor

Re: Scripting deleting files older than XX number of days

find /interface//archive
-mtime +90 -exec rm {} \;

assuming you're deleting files on the system you're logged into and not a remote system.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Chad Brindley
Regular Advisor

Re: Scripting deleting files older than XX number of days

Hi all
Thanks for the replies.
I've entred the command below to test lisitng the files before using the rm command:

find /interface/DEV/BACS -mtime +90 -exec ls {}\;

but I get the error
find: -exec not terminated with ';'

Am I missing something?

Chad (like the African Country but it's really my name)
MarkSyder
Honored Contributor
Solution

Re: Scripting deleting files older than XX number of days

You're missing a space after the } and before the \

Mark
The triumph of evil requires only that good men do nothing
Chad Brindley
Regular Advisor

Re: Scripting deleting files older than XX number of days

Doh!

Thanks all
Thanks for your speedy responses.

Chad.
Chad Brindley
Regular Advisor

Re: Scripting deleting files older than XX number of days

closed.
Thanks