在linux使用中,grep算是使用频率很高的一个命令了,今天需要在文件夹中查找一个字符串,受不了win下的速度,就在linux里面试试,特在此做个笔记,呵呵。
查看指定程序运行的情况,我们可以通过,:
ps aux | grep ‘bash’
来进行筛选指定的程序,在文件中查收也类型,同时可以加上强大的的正则表达式
grep ‘^test’file
在文件夹中查找
同样的我们在整个文件夹里面进行查找包含指定字符串的文件,即使包含在二进制文件中也逃不出grep的魔爪,呵呵,比如我要在debug目录中查找包含fhmainctl字符串的文件:
grep fhmainctl . –r
查找结果:
[root@bld112 montavista]# grep fhmainctl -r .
./fhagentflst: $(OBJDIR)/fhmainctl01.o
Binary file ./debug/fhsi matches
Binary file ./debug/fhagent.o matches
Binary file ./debug/fhmainctl01.o matches
Binary file ./debug/libfhagent.a matches其实就是加了一个-r参数,就搞定了,man grep看看,怎么解释的
-R, -r, –recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.当然通过
find . | xargs grep fhmainctl
查找结果也是一样的

