如何使用 grep 的绝对路径搜索特定文件中的字符串

如何使用 grep 的绝对路径搜索特定文件中的字符串

我想使用绝对路径在几个文件中搜索某个字符串,比如我想在几个 java 文件中找到所有出现的 inheritDoc ,我尝试了以下命令:

grep -inr \
--include /opt/li/projects/universign-copy-2/universign/universign-server/src/com/cryptolog/universign/server/HealthCheckHandler.java \
--include /opt/li/projects/universign-copy-2/universign/universign-admin-www/src/com/cryptolog/universign/admin/actions/HealthCheckAction.java \
--include /opt/li/projects/universign-copy-2/universign/universign-www/src/com/cryptolog/universign/www/action/HealthCheckAction.java \
--include /opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/HealthCheckConfiguration.java \
--include /opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/HealthCheckResult.java \
--include /opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/utils/HealthCheckUtils.java \
--include /opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/utils/HttpUtils.java \
inheritDoc

但那不管用。我怎么才能做到这一点?

答案1

虽然您已为“--include”指定了文件模式(它将覆盖先前由“--exclude”参数排除的任何文件),但您实际上并未列出要搜索的文件。请尝试:

grep -inr inheritDoc \
/opt/li/projects/universign-copy-2/universign/universign-server/src/com/cryptolog/universign/server/HealthCheckHandler.java \
/opt/li/projects/universign-copy-2/universign/universign-admin-www/src/com/cryptolog/universign/admin/actions/HealthCheckAction.java \
/opt/li/projects/universign-copy-2/universign/universign-www/src/com/cryptolog/universign/www/action/HealthCheckAction.java \
/opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/HealthCheckConfiguration.java \
/opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/HealthCheckResult.java \
/opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/utils/HealthCheckUtils.java \
/opt/li/projects/universign-copy-2/universign/universign-core/src/com/cryptolog/universign/core/utils/HttpUtils.java 

并检查“man grep”以获取更多信息。

相关内容