当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 2 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : find -exec问题请教
帖子发表于 : 2015-03-21 13:44 

注册: 2007-02-05 13:07
帖子: 57
送出感谢: 1
接收感谢: 0 次
代码:
find -name ‘*.c’ -exec grep -l abc {} \;


请问find的-exec里{} 和\;代表什么意思?
grep里加了-l 只显示文件名,能文件名和内容一起显示吗?

谢谢了


页首
 用户资料  
 
2 楼 
 文章标题 : Re: find -exec问题请教
帖子发表于 : 2015-03-21 16:51 
头像

注册: 2008-09-18 13:11
帖子: 2781
送出感谢: 1
接收感谢: 453
要学会查manpage,里面解释得很清楚
引用:
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of `;' is encountered
. The string `{}'
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command
, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a `\') or quoted to
protect them from expansion by the shell
. See the EXAMPLES sec‐
tion for examples of the use of the -exec option. The specified
command is run once for each matched file. The command is exe‐
cuted in the starting directory. There are unavoidable secu‐
rity problems surrounding use of the -exec action; you should
use the -execdir option instead.


想要同时显示内容和文件名,可以用-H参数
代码:
find -name '*.c' -exec grep -H abc {} \;


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 2 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 0 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译