unix 管道命令与 find 的混合
要获取“compact”目录中包含“measure_remove”一词的文件名, 我发出了这个命令。
find ./compact/ -type f -exec grep -n 'measure_remove' {} \ -exec ls {} \;
- grep: ls: '没有这样的文件或目录'
- grep: -exec: '没有这样的文件或目录'
- ./compact/prepare.js:44509: = "measure_remove";
- grep : ls: '没有这样的文件或目录'
- grep: -exec: '没有这样的文件或目录'
它可以工作,但我只想获取文件名和结果。 有不止一种方法吗?
To get file names which contains the word 'measure_remove' in 'compact' directory,
I made this command.
find ./compact/ -type f -exec grep -n 'measure_remove' {} \ -exec ls {} \;
- grep: ls: 'there are no such file or directory'
- grep: -exec: 'there are no such file or directory'
- ./compact/prepare.js:44509: = "measure_remove";
- grep: ls: 'there are no such file or directory'
- grep: -exec: 'there are no such file or directory'
It works but i just want to get file names and result.
is there more than one way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想匹配文件名,请将 -l (el) 传递给 grep:
如果您还希望行匹配,某些 grep 接受 -H,但如果您给它 2 个文件名,则所有 grep 都应该打印文件名。一种常见的技术是将 /dev/null 作为第二个文件传递以进行搜索:
If you just want the filenames that match, pass -l (el) to grep:
If you also want the line matches, some grep accept -H, but all grep should print the file name if you give it 2 file names. A common technique is to pass /dev/null as a second file to search: