Page 1 of 1
[SOLVED] delete files older then 7 days (shell)
Posted: Fri Sep 12, 2008 6:41 am
by rsmarsha
Just wondering if anyone can help me with a shell script.
I need to delete all csv files in a folder older than 7 days. I know how to delete and other basic shell stuff but not sure how to do it on files older than 7 days.
Any pointers would be great.

Re: delete files older then 7 days (shell)
Posted: Fri Sep 12, 2008 7:27 am
by VladSun
http://unixhelp.ed.ac.uk/CGI/man-cgi?find
You will need either
-mtime,
-ctime or
-atime, depending on your needs.
Also, you may use
Code: Select all
find .... -exec command_here '{}' \;
Or
Re: delete files older then 7 days (shell)
Posted: Fri Sep 12, 2008 8:16 am
by rsmarsha
Thanks,
Does this look right to you?
find $DIR -type f -atime +7 -exec rm -f {} \; -print
Re: delete files older then 7 days (shell)
Posted: Fri Sep 12, 2008 9:39 am
by VladSun
Yes, it looks good

Just be carefull with it

Re: delete files older then 7 days (shell)
Posted: Fri Sep 12, 2008 9:41 am
by rsmarsha
Hehe had to make a bit of a change.
find /var/www/html/fredflintstone/exported_orders/done -mtime +6 -exec rm -f {} \;
was the one I settled on after a bit of googling.
Thanks for the help