23,125
社区成员
发帖
与我相关
我的任务
分享
find /etc -type f | grep '\*'
find /etc -type f |xargs grep '\*'
ifconfig eth0 | grep 'inet addr'
grep本身不就是管道命令吗?
鸟叔书上写的
你这种写法加不加xargs根本就是两个不同的命令。 第一行 find /etc -type f | grep '\*' 这是在find的结果中,找带*的行,这个结果是指find出来的"文件名"。如果文件名中没有*,那就没输出。 类似于echo 'file1 file2 ... ' | grep '\*' 第二行 find /etc -type f |xargs grep '\*' 这是将find的结果,作为参数传给grep,也就是说让grep去这个结果的文件内容里去找带 '*'的行。相当于 grep '\*' file1 file2 ... 第三行 ifconfig eth0 | grep 'inet addr' 这是在ifconfig的结果中查找'inet addr',如果你这时候带了xargs,会将ifconfig的结果作为一个个文件名去grep,你会得到一堆找不到文件的报错。
想问下,第一行的命令执行为什么没结果?grep本身不就是管道命令吗? 第三行为什么不加就可以?find /etc -type f | grep '\*' find /etc -type f |xargs grep '\*' ifconfig eth0 | grep 'inet addr'