我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
使用 pwd 从您所在的任何目录中搜索,向下滑动
grep -rnw `pwd` -e "pattern"
取决于您正在使用的 grep 版本,您可以忽略 pwd. 在更新的版本中,如果没有目录,则似乎是 grep 的默认情况。
这样:
格雷普 -rnw -e “模式”
或
格雷普 -rnw “模式”
他们会像上面那样做!
其他回答
下面是可以用于搜索文件的几个命令列表。
grep "text string to search” directory-path
grep [option] "text string to search” directory-path
grep -r "text string to search” directory-path
grep -r -H "text string to search” directory-path
egrep -R "word-1|word-2” directory-path
egrep -w -R "word-1|word-2” directory-path
使用 pwd 从您所在的任何目录中搜索,向下滑动
grep -rnw `pwd` -e "pattern"
取决于您正在使用的 grep 版本,您可以忽略 pwd. 在更新的版本中,如果没有目录,则似乎是 grep 的默认情况。
这样:
格雷普 -rnw -e “模式”
或
格雷普 -rnw “模式”
他们会像上面那样做!
grep -lrnw '/root/Desktop/ipozal' -e 'geolocation'
例如:
我的文件夹名称是“Ipozal”它放在“/root/Desktop”我想在所有文件中找到此文本“地理位置”
找到与 xargs 是优先的,当有许多潜在的比赛可以通过. 它运行比其他选项更慢,但它总是工作. 正如一些发现,xargs 不处理文件与嵌入空间默认。
这里是 @RobEarl 的答案,增强,以便处理文件与空间:
find / -type f | xargs -d '\n' grep 'text-to-find-here'
下面是 @venkat 的答案,同样增强:
find . -name "*.txt" | xargs -d '\n' grep -i "text_pattern"
这里是 @Gert van Biljon的答案,同样增强:
find . -type f -name "*.*" -print0 | xargs -d '\n' --null grep --with-filename --line-number --no-messages --color --ignore-case "searthtext"
以下是 @LetalProgrammer 的答案,同样增强:
alias ffind find / -type f | xargs -d '\n' grep
这里是 @Tayab Hussain的答案,同样增强:
find . | xargs -d '\n' grep 'word' -sl
您可以使用捕捉工具重复搜索当前文件夹,如:
grep -r "class foo" .
注意: -r - 重复搜索分支机构。
grep "class foo" **/*.c
如果你有错误,你的论点太长,考虑缩短你的搜索,或者使用找到合成代替,如:
find . -name "*.php" -execdir grep -nH --color=auto foo {} ';'
或者使用Ripgrep。
rg "class foo" .
它比任何其他工具,如 GNU/BSD grep, ucg, ag, sift, ack, pt 或类似,因为它是建立在Rust的 regex 引擎的顶部,使用终端自动化,SIMD和攻击性字体优化,使搜索非常快。
-i - 不敏感的搜索. -I - 忽略二进制文件. -w - 搜索完整的单词(相反的部分单词匹配)。 -n - 显示您的匹配线. -C/--背景(例如 -C5) - 增加背景,所以你看到周围的代码. --color=auto - 标记匹配文本. -H - 显示文件名,在文本中找到。