No such file or directory find command on linux [closed]

风格不统一 提交于 2021-02-17 06:30:25

问题


I've created script which delete old backup file from directory but this command was worked fine before 1 week and Nothing change on script or packages but still getting below error:

root@:# find /var/backups/abc/* -type d -mtime +6
/var/backups/abc/2016-03-09_0321

root@:~# find /var/backups/abc/* -type d -mtime +6 -exec rm -rf {} \;
find: `/var/backups/abc/2016-03-08_0321': No such file or directory 

Problem is that, this script run every day on cron, I getting a mail like " find: `/var/backups/abc/2016-03-08_0321': No such file or directory". files are deleted but such a mails are getting from root.


回答1:


find /var/backups/abc/* -type d -mtime +6 -prune -exec rm -rf {} \;

Here, we use -prune on the directories that we're about to delete, so find will then not try to read their contents.




回答2:


This is because of after having returned your directory, find will try to look in it (to continue his recursive search), and will fail because of you just removed it.



来源:https://stackoverflow.com/questions/36003434/no-such-file-or-directory-find-command-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!