Pan*_*ndu 7 unix directory grep find
我使用以下命令在目录结构中递归地查找字符串.
find . -exec grep -l samplestring {} \;
Run Code Online (Sandbox Code Playgroud)
但是当我在一个大型目录结构中运行命令时,会有一个很长的列表
grep: ./xxxx/xxxxx_yy/eee: Is a directory
grep: ./xxxx/xxxxx_yy/eee/local: Is a directory
grep: ./xxxx/xxxxx_yy/eee/lib: Is a directory
Run Code Online (Sandbox Code Playgroud)
我想省略上面的结果.只需显示带有字符串的文件名即可.有人可以帮忙吗?
无论何时你说find .,该实用程序将返回当前目录结构中的所有元素:文件,目录,链接......
如果你只是想找到文件,就这么说吧!
find . -type f -exec grep -l samplestring {} \;
# ^^^^^^^
Run Code Online (Sandbox Code Playgroud)
但是,您可能希望查找包含字符串的所有文件:
grep -lR "samplestring"
Run Code Online (Sandbox Code Playgroud)
grep -s 要么 grep --no-messages
这是值得一读的便携笔记的GNU grep的文件,如果你希望使用此代码的多个位置,但:
-s
--no-messages
Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep’s -q option.1 USG-style grep also lacked -q but its -s option behaved like GNU grep’s. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. (-s is specified by POSIX.)
| 归档时间: |
|
| 查看次数: |
4760 次 |
| 最近记录: |