ele*_*n81 0 grep shell-script find
我试图在我硬盘上某处的文件中找到特定的文本字符串。到目前为止,我想出的最好的是:
find -type f / | xargs cat | grep "string to find"
Run Code Online (Sandbox Code Playgroud)
但这只是告诉我字符串是否存在于某处。
我怎么知道我在哪个文件中找到了它?
有没有更好的办法?
这应该可以解决问题,而且要简单得多:
grep -R "some string" /
Run Code Online (Sandbox Code Playgroud)
添加 -n 将显示您需要的行号:
grep -Rn "some string" /
Run Code Online (Sandbox Code Playgroud)