【发布时间】:2013-11-09 04:59:57
【问题描述】:
我的要求和这个问题差不多:Shell script to delete directories older than n days 我的目录如下所示:
Jul 24 05:46 2013_07_24
Jul 31 22:30 2013_08_01
Sep 18 05:43 2013_09_18
Oct 07 08:41 2013_10_07
我想删除超过 90 天的所有内容。基于上述线程中给出的解决方案,我在脚本中使用了以下内容:
find $BASE_DIR -type d -ctime +90 -exec rm -rf {} \;
脚本已成功删除目录,但也因以下错误而失败:
find: 0652-081 cannot change directory to <actual_path>:
: A file or directory in the path name does not exist.
这里唯一 $BASE_DIR 指向的位置是虚拟位置,而错误消息中的 actual_path 指向实际位置。环境中有软链接。
【问题讨论】:
-
你能发布
find $BASE_DIR -type d -ctime +90的输出吗?它试图删除的目录似乎已被删除,因此无法引用指向它的符号链接。 -
也许还使用
-depth有帮助? -
我需要做更多的测试,但
-depth似乎摆脱了错误。谢谢!