通过复杂目录(代码、文件、php 脚本等)诊断缓慢的 grep 或 ack 搜索,以便更快地重复使用

发布于 2024-10-29 21:31:40 字数 599 浏览 2 评论 0原文

我正在使用 ack (有时作为 ack-grep 分发)来搜索复杂的代码、图像目录,谁知道还有什么,而且它的反应非常慢。我如何诊断它正在搜索的内容导致速度变慢,以便我可以让它忽略它们?

我刚刚意识到我的 ack-grep 缓慢的原因可能会因为同样的原因而使 grep 缓慢,所以我更改了标题的措辞以引用两者。

当前 ack-grep 命令别名:

function view ()
{
echo "ack-grep -i $@ // ignoring third-party directories"
ack-grep -i --ignore-dir=third-party --ignore-dir="unclean-files" --ignore-dir=FCKeditor --ignore-dir=smarty --ignore-dir=codepress --ignore-dir=yui "$@"
}

因此,我通过该别名对某些字符串进行不区分大小写的搜索,例如查看“哎呀!必填字段”,忽略某些目录。

我想我真正可以使用的是 grep 或 ack-grep 的“详细”模式,这样我就可以直观地看到它悬挂的子目录,因为它们搜索速度很慢。

I'm using ack (sometimes distributed as ack-grep) to search through a complex directory of code, images, who knows what else, and it's reacting pretty slowly. How can I diagnose what it is searching through that is making it slow, so that I can have it ignore 'em?

I just realized that the reasons that my ack-grep are slow will probably make grep slow for the same reason, so I've changed the wording of the title to refer to both.

Current ack-grep command alias:

function view ()
{
echo "ack-grep -i $@ // ignoring third-party directories"
ack-grep -i --ignore-dir=third-party --ignore-dir="unclean-files" --ignore-dir=FCKeditor --ignore-dir=smarty --ignore-dir=codepress --ignore-dir=yui "$@"
}

So I do a case-insensitive search on some string via that alias, e.g. view "Oops! Required fields", ignoring certain directories.

I guess what I could really use is a "verbose" mode to either grep or ack-grep, so that I can visually see subdirectories that it hangs around on because they're slow to search.

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

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

发布评论

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

评论(2

森林很绿却致人迷途 2024-11-05 21:31:40

最终使用 -L 开关使其输出所有匹配的文件,以便快速直观地诊断问题。仅使用以下命令结构:

ack-grep -L "哎呀!必填字段未全部完成。"

Ended up using the -L switch to make it output all the files that it matches, for quick visual diagnosis of problems. Used just the command structure below:

ack-grep -L "Oops! Required fields were not all completed."

一片旧的回忆 2024-11-05 21:31:40

你在寻找什么?如果它只是特定类型的源(假设您正在寻找变量),请使用适当的开关(对于 perl,使用 --perl 等)。如果你有大量的资源,那么无论你做什么都需要一段时间。

Ack-grep 的智能程度取决于您的描述。另外,你的正则表达式有多复杂?正则表达式有开销,如果您只是搜索某个名称,请不要使用正则表达式。您不应该使用锤子来松开螺栓。

What are you searching for? If it's just source of a particular type (say you're looking for a variable), use the appropriate switch (for perl, use --perl, etc). If you have tons of source, it's gonna take a while regardless of what you do.

Ack-grep is only as smart as you tell it to be. Also, how complex is your regex? Regex has overhead, and if you're just searching for a name of something, don't use regex. You shouldn't use a hammer to loosen a bolt.

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