如何递归地grep所有目录和子目录?
find . | xargs grep "texthere" *
如何递归地grep所有目录和子目录?
find . | xargs grep "texthere" *
当前回答
grep-r“texthere”。(通知期结束)
(^信用:https://stackoverflow.com/a/1987928/1438029)
澄清:
grep-r“texthere”/(递归地grep所有目录和子目录)
grep-r“texthere”。(递归地grep这些目录和子目录)
grep递归
grep[选项]模式[文件…][选项]-R、 -R,--递归递归地读取每个目录下的所有文件。这相当于-d recurse或--directories=recurse选项。http://linuxcommand.org/man_pages/grep1.html
grep帮助
$grep--帮助
$ grep --help |grep recursive
-r, --recursive like --directories=recurse
-R, --dereference-recursive
选择
确认(http://beyondgrep.com/)
银(http://github.com/ggreer/the_silver_searcher)
其他回答
在POSIX系统中,找不到grep的-r参数和grep-rn“东西”。不会运行,但如果使用find命令,它将:
查找-键入f-exec grep-n“stuff”{}\-打印
Solaris和HP-UX同意。
下面是在Unix和Linux环境中递归搜索字符串的命令。
对于UNIX命令是:
find . -name "string to be searched" -exec grep "text" "{}" \;
对于Linux,命令是:
grep -r "string to be searched" .
只是为了好玩,如果@christangrant的答案太多而无法输入,可以快速搜索*.txt文件:-)
grep-r文本此处|grep.txt文件
在IBM AIX Server(操作系统版本:AIX 5.2)中,使用:
find ./ -type f -print -exec grep -n -i "stringYouWannaFind" {} \;
这将打印出文件中的路径/文件名和相对行号,如:
./inc/xxxx_x.h
2865:/**描述:stringYouWanna查找*/
无论如何,这对我来说很有用:)
有关可用标志的列表:
grep --help
返回当前目录中此处的regexp文本的所有匹配项,以及相应的行号:
grep -rn "texthere" .
返回文本的所有匹配项,从根目录开始,具有相应的行号,忽略大小写:
grep -rni "texthere" /
此处使用的标志:
-r递归-n带输出的打印行号-我不理这个案子