I am using Ubuntu 10.04 lts
I am looking for the correct command line to delete all files from folder /var/www/myfolder/pictures/ every 30 days.
What is the command I should apply to crontab -e?
I am also using php5 on my server.
|
I am using Ubuntu 10.04 lts I am looking for the correct command line to delete all files from folder /var/www/myfolder/pictures/ every 30 days. What is the command I should apply to crontab -e? I am also using php5 on my server. |
|||||||||
|
Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.
|
You can use find. This will find files older than 30 days and delete them
to run it on the 2nd of the month at 12:30 am from root's crontab (using
As you are using ubuntu you could also use /etc/cron.monthly/standard which is run at
|
|||
|
|
Find is your friend here.
You'll probably want to put some sanity checking around this in a script if you are going to put it in a script though. |
|||||||||
|
|
Aside from find, if you mean remove files older than a given date, you can also use tmpwatch, which is designed to remove files created or modified beyond a given time.
you can also do 30d instead of 720 (hours) Reading your actual question though it sounds like you want to remove all files every 30 days, rather than remove files older than 30 days, which isn't quite the same thing. By 30 days, do you actually mean once a month ? If so, you can use @monthly in crontab and just run a rm on the folders contents.
If not you can do:
Or you can fire tmpwatch off from cron (but it seems like you might as well use cron for the scheduling and just do an rm, it'll save cpu time just to prove everything in the dir is in fact new since the last time you removed everything, which seems a bit redundant to me). Should get you started |
||||
|
|