我想在晚上 11:30 删除所有超过 30 天的 pdf 文件
我在 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
最佳答案
您错过了用户和路径。这可能有帮助
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
30 23 * * * root find /var/www/html/site/reports/ \( -name "*.pdf" \) -type f -mtime +30 -exec rm {} \; >> /tmp/debug_cron 2>&1
然后检查/tmp/debug_cron
关于linux - crontab 没有删除 linux 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32848720/