find . –maxdepth 1 –exec grep leon {} \;
上面的命令, 虽然找到了当前目录下的哪个文件有 leon 这个字符串, 但是并没有写出文件是什么.
find . –maxdepth 1 | xargs grep leon;
这个命令达到了我想要的效果.
另外, 通过 ls | xargs grep leon; 也可以达到我要的效果
但是, ls | grep leon ; 直接这么使用就不行.
分析:
| 管道命令是前一个命令的输出standout 被后一个命令所读取
ls | grep leon, 这个命令, 前面输出的是屏幕上显示的内容, 只是字符, 后边 grep 截取命令只是在这些字符中截取是否有 leon 这个字符
而 xargs 是将前一个命令的结果作为 standin, 这就好比 grep leon 文件名(输入内容), 这肯定是可以找到的.
总之, 还是有点迷糊, 不过实验成功了.
原文:http://www.cnblogs.com/moveofgod/p/3548326.html