`
chenzhou123520
  • 浏览: 4249869 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

linux报错 find: missing argument to `-exec'

阅读更多

在linux下使用find命令时,报错:find: missing argument to `-exec'

具体执行命令为:

find /u03 -name server.xml -exec grep '9080' {}\;

目的是查找/u03目录下名称为server.xml的文件,根据查找的结果进行grep搜索,搜索其中包含9080的文本。 

-exec语法格式为: 

-exec command {} \;

在{}和\之间必须要有空格,否则会报上面的错。 

加上空格之后重新执行命令:

find /u03 -name server.xml -exec grep '9080' {} \;

结果:

<Connector port ="9080" redirectPort ="9443" connectionTimeout ="20000" URIEncoding ="utf-8" 
               port="9080" protocol="HTTP/1.1" 
               port="9080" protocol="HTTP/1.1" 
<Connector port ="9080" redirectPort ="9443" connectionTimeout ="20000" URIEncoding ="utf-8" 
               port="9080" protocol="HTTP/1.1" 
分享到:
评论
3 楼 chenzhou123520 2014-06-17  
寂寞秋江 写道
哦,原来 \ 的意思,是作为转义字符来用的,所以必须跟;紧挨着:

“对于不同的系统,直接使用分号可能会有不同的意义, 使用转义符 '\'在分号前明确说明”

详见:http://www.itzhai.com/linux-find-sed-tr-grep-cut-wc-and-other-commonly-used-commands-and-related-instances-of-the-use-of-analytical.html

  
2 楼 寂寞秋江 2014-06-12  
哦,原来 \ 的意思,是作为转义字符来用的,所以必须跟;紧挨着:

“对于不同的系统,直接使用分号可能会有不同的意义, 使用转义符 '\'在分号前明确说明”

详见:http://www.itzhai.com/linux-find-sed-tr-grep-cut-wc-and-other-commonly-used-commands-and-related-instances-of-the-use-of-analytical.html
1 楼 寂寞秋江 2014-06-12  
除了博主提到的 “{}和\之间必须要有空格” 这个坑外,

还有另外一个坑:

\  和  ; 之间不能有空格,否则同样报错:“find: missing argument to `-exec'”

相关推荐

Global site tag (gtag.js) - Google Analytics