如何在没有搜索猴子的Windows中搜索文件中的字符串?

我在VMWare上使用Ubuntu但由于安全限制我无法连接到Internet。

我想知道是否有办法通过终端搜索字符串,并找到该字符串在文件中的哪一行。

列出的选项太多了

 grep -r 'pattern_to_match' directory_to_search 

将输出文件名和与模式匹配的完整行。

我使用的最好的是grep命令和选项-ri(递归和不区分大小写的搜索):

 $ grep -r  directory_or_path_to_search 

可能对您有用的选项:

  -i - case insensitive -r, --recursive like --directories=recurse -R, --dereference-recursive likewise, but follow all symlinks --include=FILE_PATTERN search only files that match FILE_PATTERN --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN --exclude-from=FILE skip files matching any file pattern from FILE --exclude-dir=PATTERN directories that match PATTERN will be skipped. 

如果您只想查找sting位于文件中的行号,请使用以下命令:

 grep -n '/string_To_Find/=' directory/file_Name 

如果要查找行号并输出字符串所在行的完整行名,请使用以下命令:

 grep -n 'string_To_Find' directory/file_Name 

如果您只想查找字符串所在的完整行名称,请使用以下命令:

 grep -r 'string_To_Find' directory/file_Name