浅谈Linux下通过find命令进行rm文件删除的小技巧

2019-10-13 13:59:31王旭

通过以上操作我们可以看到,find命令不单查询了/enterprisedb_backup/postgresql/目录,并且遍历了所有子目录,因此支持了我们的推断

4.综上所述基本定位问题所在

解决方案:

1.整理思路后,可以确认,如果find只找出所需操作目录的第1层文件及目录即可解决此问题

2.通过伟大的 man 命令我们得到以下信息

-maxdepth levels
  Descend at most levels (a non-negative integer) levels of directories below the command line arguments. -maxdepth 0 means only apply the tests and actions to the command line arguments. 

3.测试操作确认修改为:

[root@edbnode1 ~]# /bin/find /enterprisedb_backup/postgresql/ -mtime +7 -maxdepth 1 -exec /bin/rm -rf {} ;
/bin/find: warning: you have specified the -maxdepth option after a non-option argument -mtime, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

这里意思是说:-mtime找到的信息可能会操过-maxdepth的范围,在find操作中建议-maxdepth放在所有其他参数的前面

解决结果【完成】

以上这篇浅谈Linux下通过find命令进行rm文件删除的小技巧就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易采站长站。