我有一个脚本来清理日志区域中的旧文件和目录,如:
find . -mtime +${NUM_DAYS} -type d -exec rm -rf '{}' \;
但是,如果我从已更改的文件中运行这2个级别,它通常会显示父目录,因为时间戳不会被更改的子目录
有没有一种方法,我可以使用查找(或其他),所以我不试图删除父目录?
例如,如果我有文件系统:
# ls -ld /var drwxr-xr-x 24 root root 4096 Aug 16 2010 /var # ls -ld /var/net-snmp/ drwx------ 2 root root 4096 Aug 28 15:49 /var/net-snmp/ # ls -l /var/net-snmp/ total 4 -rw------- 1 root root 1174 Aug 28 15:49 snmpd.conf
从/运行我的find命令将试图recursion地删除/ var,即使NUM_DAYS被设置为8月28日在我的时间范围内
您可以使用-mindepth选项:
-mindepth levels Do not apply any tests or actions at levels less than levels (a non-negative integer). -mindepth 1 means process all files except the command line arguments.
假设linux,我会给tmpwatch一个尝试。