2010-12-02 187 views
3

我有這樣的cron作業以清空臨時文件夾之前創建的文件我每天一次:cron作業刪除特定時間

rm -rf /home/username/public_html/temp/* 

我想這個cron作業刪除其之前創建的所有文件將運行5分鐘以上,以確保我的腳本不再需要這些文件。

比方說,我設定的cron作業日上午10:00每天跑..我想它刪除此文件夾,其09:55之前創建的所有文件中的AM

謝謝你這麼多的專家!

回答

2

如果您使用GNU find,試試這個:

find /home/username/public_html/temp -type f -mmin +5 -delete 

也應該從FreeBSD或find許多其他版本。

+0

我使用的cPanel。 – Dido 2010-12-04 05:13:36

0

替代的解決方案是: -

點cron作業來執行PHP文件,每日一次。

$dir = 'your/directory/'; 
    foreach(glob($dir.'*.*') as $v){ 
    $last_modified = filemtime($v);//get the last modified time of file 
    $fmtime=date("h:i:s", $last_modified); 
    $currentTime=date("h:i:s"); 

    if (//check here if your file is created before 09:55Am) 
    unlink($v); 

    } 

謝謝。

+1

Glob`*。*`??我認爲你的DOS正在顯示。這隻會匹配名稱中帶有點的文件。 – 2010-12-02 07:14:40

0

到傑弗里斯答案類似,我建議是這樣的:

for i in `find /home/username/public_html/temp -type f -mmin +5` 
    do rm $i 
done