简体   繁体   English

如何在没有前导目录名称的情况下为exec查找传递文件名?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM