unix 管道命令与 find 的混合

发布于 2024-12-22 19:46:17 字数 433 浏览 1 评论 0原文

要获取“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-12-29 19:46:17

如果您只想匹配文件名,请将 -l (el) 传递给 grep:

$ find compact -type f -exec grep -l 'measure_remove' {} \;

如果您还希望行匹配,某些 grep 接受 -H,但如果您给它 2 个文件名,则所有 grep 都应该打印文件名。一种常见的技术是将 /dev/null 作为第二个文件传递以进行搜索:

$ find compact -type f -exec grep -n measure_remove /dev/null {} \;

If you just want the filenames that match, pass -l (el) to grep:

$ find compact -type f -exec grep -l 'measure_remove' {} \;

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:

$ find compact -type f -exec grep -n measure_remove /dev/null {} \;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文