Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.
Moderator: General Moderators
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Fri Sep 12, 2008 6:41 am
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.
Last edited by
rsmarsha on Fri Sep 12, 2008 9:42 am, edited 1 time in total.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Sep 12, 2008 7:27 am
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
There are 10 types of people in this world, those who understand binary and those who don't
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Fri Sep 12, 2008 8:16 am
Thanks,
Does this look right to you?
find $DIR -type f -atime +7 -exec rm -f {} \; -print
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Sep 12, 2008 9:39 am
Yes, it looks good
Just be carefull with it
There are 10 types of people in this world, those who understand binary and those who don't
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Fri Sep 12, 2008 9:41 am
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