使用 grep 查找文件

发布于 2024-11-25 23:22:59 字数 177 浏览 5 评论 0原文

我想找到包含一些我感兴趣的内容的文件。我希望该文件的扩展名为 .h 或 .cc。有没有比输入两次更快的方法:

grep -r "some stuff" * --include="*.h"
grep -r "some stuff" * --include="*.cc"

I want to find file containing some interesting stuff for me. I want that file to have extension .h or .cc. Is there some faster way than typing two times:

grep -r "some stuff" * --include="*.h"
grep -r "some stuff" * --include="*.cc"

?

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

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

发布评论

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

评论(1

滥情稳全场 2024-12-02 23:22:59

我在 .bashrc 中定义了一个 bash 函数,它在当前目录中递归搜索,但跳过已知不感兴趣的文件和目录:

function cgrep () {
    egrep -nrI --color=auto --exclude="*.svn-base" --exclude=".svn" --exclude="entries" --exclude=".*.d" --exclude="cscope.out" --exclude="*.syms" --exclude="*.dis" --exclude="*.d" "$@" .
}

通过调用它

> cgrep uint64_t
./fs/nfsd/nfs4xdr.c:3016:   uint64_t minor_id = 0;
./fs/nfs/callback.h:67: uint64_t size;
./fs/nfs/callback.h:68: uint64_t change_attr;
./fs/nfs/fscache-index.c:188:                      uint64_t *size)

搜索到的模式实际上是彩色的! :-)

I have a bash function defined in my .bashrc which searches in the current directory recursively but skips files and directories known to not be of interest:

function cgrep () {
    egrep -nrI --color=auto --exclude="*.svn-base" --exclude=".svn" --exclude="entries" --exclude=".*.d" --exclude="cscope.out" --exclude="*.syms" --exclude="*.dis" --exclude="*.d" "$@" .
}

Call it via

> cgrep uint64_t
./fs/nfsd/nfs4xdr.c:3016:   uint64_t minor_id = 0;
./fs/nfs/callback.h:67: uint64_t size;
./fs/nfs/callback.h:68: uint64_t change_attr;
./fs/nfs/fscache-index.c:188:                      uint64_t *size)

The searched pattern is actually colored! :-)

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