在Linux上没有这样的文件或目录查找命令 [英] No such file or directory find command on linux
问题描述
我创建了脚本,该脚本从目录中删除了旧的备份文件,但是此命令在1周前运行良好,脚本或软件包没有任何变化,但仍然低于错误:
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
问题在于,该脚本每天在cron上运行,我收到类似"find:`/var/backups/abc/2016-03-08_0321'的邮件:没有这样的文件或目录".文件已删除,但此类邮件是从根目录获取的.
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.
推荐答案
find /var/backups/abc/* -type d -mtime +6 -prune -exec rm -rf {} \;
在这里,我们在要删除的目录上使用 -prune
,因此 find
不会尝试读取其内容.
Here, we use -prune
on the directories that we're about to delete, so find
will then not try to read their contents.
这篇关于在Linux上没有这样的文件或目录查找命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!