加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 使用查找删除早于n天的目录

发布时间:2020-12-16 01:58:01 所属栏目:安全 来源:网络整理
导读:我的要求与这个问题几乎相同: Shell script to delete directories older than n days 我的目录看起来像这样: Jul 24 05:46 2013_07_24Jul 31 22:30 2013_08_01Sep 18 05:43 2013_09_18Oct 07 08:41 2013_10_07 我想删除超过90天的任何内容.基于前面提到的
我的要求与这个问题几乎相同: 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 -mindepth 1 -maxdepth 1 -type d -ctime +90 -exec rm -rf  {} ;

这将仅覆盖$BASE_DIR下的目录,但应避免生成该错误消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读