Unix bash 命令

发布于 2024-09-17 12:49:34 字数 51 浏览 3 评论 0原文

如何编写一个 bash 命令来查找当前目录中包含单词“foo”的所有文件(无论大小写)?

How to write a bash command that finds all files in the current directory that contain the word “foo”, regardless of case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

笔落惊风雨 2024-09-24 12:49:34

如果您希望根据 . 中的文件竞争检查“foo”,请执行以下操作:

grep . -rsni -e "foo"

有关更多选项(-I、-T、...),请参阅 man grep< /代码>。

If you want "foo" to be the checked against the contests of the files in ., do this:

grep . -rsni -e "foo"

for more options (-I, -T, ...) see man grep.

颜漓半夏 2024-09-24 12:49:34

假设您想在文件内部搜索(而不是文件名)

如果您只想搜索当前目录(而不是树)

grep * -nsie "foo"

如果您想扫描整个树(从当前目录)

grep . -nsrie "foo"

Assuming you want to search inside the files (not the filenames)

If you only want the current directory to be searched (not the tree)

grep * -nsie "foo"

if you want to scan the entire tree (from the current directory)

grep . -nsrie "foo"
倥絔 2024-09-24 12:49:34
shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..
shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..
苏大泽ㄣ 2024-09-24 12:49:34

Try:

echo *foo*

将打印当前目录中与 *foo* 匹配的文件/目录名称,该名称恰好与包含“foo”的任何名称匹配。

Try:

echo *foo*

will print file/dir names matching *foo* in the current directory, which happens to match any name containing 'foo'.

慵挽 2024-09-24 12:49:34

我一直使用这个小 shell 命令:

gfind () { if [ $# -lt 2 ]; then files="*"; search="${1}"; else files="${1}"; search="${2}"; fi; find . -name "$files" -a ! -wholename '*/.*' -exec grep -Hin ${3} "$search" {} \; ; }

您可以通过 gfind '*php' 'search string' 来调用它,或者如果您想搜索所有文件 gfind 'search string' >

I've always used this little shell command:

gfind () { if [ $# -lt 2 ]; then files="*"; search="${1}"; else files="${1}"; search="${2}"; fi; find . -name "$files" -a ! -wholename '*/.*' -exec grep -Hin ${3} "$search" {} \; ; }

you call it by either gfind '*php' 'search string' or if you want to search all files gfind 'search string'

扛起拖把扫天下 2024-09-24 12:49:34

寻找 。 -类型 f | grep -i“foo”

find . -type f | grep -i "foo"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文