我想在下午11:30的crontab不刪除的文件在Linux
刪除所有的PDF文件,其中有30多天我加了如下代碼在crontab中
30 23 * * * find /var/www/html/site/reports/ -name "*.pdf" -type f -mtime +30 | xargs -I {} rm -f {} \;
但它不會刪除這些文件。
你可以請檢查是什麼問題?
crontab的細節
-rw-r--r--. 1 root root 532 Sep 30 11:14 crontab
一個,我需要刪除
-rw-r--r-- 1 apache apache 15215 Jul 25 11:24 sales_report.pdf
'+ 30'意味着** **以上30天以內。所以正好30天的文件不會被刪除。 – Barmar
最後不需要'\;' - 這是爲了當你使用'find -exec'時,它不是'xargs'的一部分。但是,你爲什麼不使用'-exec'? – Barmar
此外,某些版本的'find'具有刪除文件的'-delete'選項。 – Barmar