首页 > 代码库 > shell-find错误解析

shell-find错误解析

之前写过一篇文章,用shell定时清除过期文件《shell定时清除过期文件》,其实用的就是简单的find命令

后面同事采用之后,他调试脚本的时候,出现了几个错误,我做了整理:

1.find: paths must precede expression: exec

表达式不完整,在exec之前加一个执行符号“-”,就好了

2.find: missing argument to `-exec‘

根据提示,错误的参数-exec,其实是提示你表达式错误了

原本语句是这样的“find /var/log/*.log -mtime +30 -exec rm -f {}\;”

解决办法:在\前面加一个空格,特别注意

解决思路,先去man find找,刚好有find . -type f -exec file ‘{}‘ \;

这个解释够清楚了:Runs  ‘file’  on  every  file in or below the current directory.  Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation.  The semicolon is  similarly  protected by the use of a backslash, though single quotes could have been used in that case also.

--未完待续

shell-find错误解析