以前用的查找文件是否存在某个字符,并把文件名列出来:
find . –type f|xargs grep 204
结果:
./it.conf:<VirtualHost 192.168.105.204>
./sohudl.conf:<VirtualHost 192.168.105.204>
./sohunb.conf:<VirtualHost 192.168.105.204>
./travel.conf:<VirtualHost 192.168.105.204>
这个命令的分解是:
find查找出 ./it.conf ./sohudl.conf ./sohunb.conf ./travel.conf文件
然后通过xargs 把这个./it.conf ./sohudl.conf ./sohunb.conf ./travel.conf 当参数传给grep
相当于grep 204 ./it.conf ./sohudl.conf ./sohunb.conf ./travel.conf
想了想换个方式能不能行:
find . -type f -exec grep 204 {} \;
结果:
<VirtualHost 192.168.105.204>
<VirtualHost 192.168.105.204>
<VirtualHost 192.168.105.204>
<VirtualHost 192.168.105.204>
并没有想上个那样显示文件名,这个和grep有关的
命令分解:
find每次找出./it.conf 然后执行-exec把找出的文件替换掉{}结果是grep 204 ./it.conf,
其他的也是这样,这样的话grep只是分别执行了:
grep 204 ./it.conf
grep 204 ./sohudl.conf
grep 204 ./sohunb.conf
grep 204 ./travel.conf
所以grep 单个文件的时候,不会给出 文件名的,只有多个 才给出 如:
grep 204 ./it.conf ./sohudl.conf ./sohunb.conf ./travel.conf
或者grep 204 *