[英]How can I make find pass file names to exec without the leading directory name?
Someone created directories with names like source.c
. 有人创建了诸如
source.c
类的目录。 I am doing a find
over all the directories in a tree. 我正在
find
树中的所有目录。 I do want find
to search in the source.c
directory, but I do not want source.c
to be passed to the grep
I am doing on what is found. 我确实想
find
在搜索source.c
目录,但我不希望source.c
被传递到grep
我对什么是发现做。
How can I make find
not pass directory names to grep
? 我如何
find
未将目录名称传递给grep
? Here is what my command line looks like: 这是我的命令行的样子:
find sources* \( -name "*.h" -o -name "*.cpp" -o -name "*.c" \) -exec grep -Hi -e "ThingToFind" {} \;
Add -a -type f
to your find
command. 在
find
命令中添加-a -type f
。 This will force find
to only output files, not directories. 这将强制
find
仅输出文件,而不是目录。 (It will still search directories): (它仍然会搜索目录):
find sources* \( -name "*.h" -o -name "*.cpp" -o -name "*.c" \) -a -type f -exec grep -Hi -e "ThingToFind" {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.