为什么递归grep似乎不起作用?

时间:2019-02-28 05:29:29

标签: grep

grep的手册页上说:

-r, --recursive
          Read all files under each directory, recursively

好的,那怎么可能:

# grep -r BUILD_AP24_TRUE apache
# grep BUILD_AP24_TRUE apache/Makefile.in
@BUILD_AP24_TRUE@mod_shib_24_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
(...)

1 个答案:

答案 0 :(得分:1)

有两种可能导致这种类型的问题:

  1. grep的别名是排除您感兴趣的文件的东西。

  2. 感兴趣的文件位于符号链接目录中,或者它本身是符号链接。

就您而言,这似乎是第二个原因。一种解决方案是使用grep -R代替grep -r。来自man grep

   -r, --recursive
          Read  all files under each directory, recursively, following symbolic
          links only if they are on the command line.  Note that if no file
          operand is given, grep searches the working directory.
          This is equivalent to the -d recurse option.

   -R, --dereference-recursive
          Read all files under each directory, recursively.
          Follow all symbolic links, unlike -r.