script for deleting files

 
rustam2
Occasional Visitor

script for deleting files

  Hi all,

 

I need to delete all files from one catalog. The main rule is - files older than sysdate - 7 days should be deleted. For instance, today is 10.04.2012.and all files older 03.04.2012 must be deleted. is it possible to have script for this situation? then i will use this script in cron job.

 

thanks and regards,

rustam2

4 REPLIES 4
Hiren N Dave
Valued Contributor

Re: script for deleting files

Try below command....

 

# find /catalog -atime +7 -exec rm -i {} \;

 

also try -ctime for findind files based on creation date

I am an HP Employee

Was this post useful? - You may click the KUDOS! star to say thank you.
rustam2
Occasional Visitor

Re: script for deleting files

 Thanks Hiren!

 

So, if i'm going to delete files from catalog /tmp/test/  i have to to run:

 

# find /temp/test/ -atime +7 -exec rm -i {} \;   

 

?

 

 

 

 

Hiren N Dave
Valued Contributor

Re: script for deleting files

Yes.

 

Check man pages for find command for -atime and -ctime usage to suit your requirements.

 

_____________________________________

How to assign points? Click the KUDOS! star!

 

I am an HP Employee

Was this post useful? - You may click the KUDOS! star to say thank you.
Dennis Handly
Acclaimed Contributor

Re: script for deleting files

># find /catalog -atime +7 -exec rm -i {} \;

 

If you want speed and limit it to normal files, you would use "+":

find /catalog -type f -atime +7 -exec rm -f {} +

 

>also try -ctime for finding files based on creation date

 

Not hardly.  -ctime is for inode change time.  Creation date isn't saved on Unix systems.

You can use -mtime for modification time.

 

>if I'm going to delete files from directory /tmp/test/  i have to to run:

 

Yes, or:

find /temp/test/ -type f -mtime +7 -exec rm -f {} +