dirgrep
dirgrep 是一个CLI工具,用于按目录执行grep操作。
它用Go编写,利用语言内置的并发特性对目录中的所有文件并发执行grep操作(甚至递归!)。
安装
为了安装 dirgrep 有三种方法:
- 使用
go:如果你已经有了go1.23+已安装在您的环境中,正在安装 dirgrep 毫不费力
go install github.com/AstraBert/dirgrep- 使用
npm:
npm install @cle-does-things/dirgrep- 正在从下载可执行文件 发布页面:您可以直接从GitHub存储库下载,或者,如果您不想离开您的终端,可以使用
curl:
curl -L -o dirgrep https://github.com/AstraBert/dirgrep/releases/download//dirgrep___
.tar.gz ## e.g. https://github.com/AstraBert/dirgrep/releases/download/0.1.1/dirgrep_0.1.1_darwin_amd64.tar.gz
# make sure the downloaded binary is executable (not needed for Windows)
chmod +x dirgrep在最后一种情况下,请注意指定您的操作系统(支持:linux、windows、macos)和处理器类型(支持:amd、arm)。
用法
dirgrep [command] [flags]命令
mcp:通过stdio传输启动MCP服务器
旗帜
-c,--context int\
匹配项周围要包含的上下文字符数。默认为 0.
-d,--directory string\
用于搜索模式的目录。默认为当前工作目录(".").
-h,--help\
显示帮助消息并退出。
-p,--pattern string\
在给定目录中搜索的模式。 必修的。
-r,--recursive\
递归搜索文件。默认为 false.
-s,--skip strings\
要跳过的一个或多个子目录。可以多次指定,也可以指定为逗号分隔的值。默认为空列表。
-x,--no-pretty
停用控制台上比赛的漂亮打印。
例子
# search for 'package main' in the current directory, excluding .git and .gitub
dirgrep --pattern 'package main' --skip .git --skip .github --recursive
# search in a specific directory non-recursively
dirgrep --pattern 'root' --directory cmd/
# add a context of 200 charachters around the match
dirgrep --pattern '202\d' --context 200
# deactivate pretty-printing
dirgrep --pattern '202\d' --context 100 --no-pretty
# start MCP server
dirgrep mcp基准
_运行基准测试需要Python 3.9+_
你可以运行 基准 dirgrep (VS其他工具)使用:
cd benchmark
bash run.sh这将:
- 在下面创建100万个文件(约4GB)
benchmark/files目录,每行包含三个随机行。 - 开始
./dirgrep搜索模式A password forgot itself at dawn.(随机行之一),将标准输出重定向到benchmark_dirgrep.txt - 开始
grep递归搜索相同的模式,将标准输出重定向到benchmark_grep.txt - 开始
ripgrep递归搜索相同的模式,将标准输出重定向到benchmark_ripgrep.txt - 一旦程序完成,您将获得它的时间输出。
在最近一次运行中, dirgrep VS其他工具执行如下:
| 度量 | dirgrep | grep | ripgrep | 描述 |
|---|---|---|---|---|
| 用户 | 35.58s | 1.53s | 2.06s | 用户模式下的CPU时间(程序代码) |
| 系统 | 454.60s | 27.67s | 38.44s | 系统模式下的CPU时间(内核操作) |
| cpu | 1166% | 17% | 312% | 所有内核的cpu利用率 |
| 总计 | 42.037秒 | 166.34秒 | 12时40分 | 实际挂钟时间 |
贡献
我们欢迎捐款!请阅读我们的 贡献指南 开始吧。
许可证
该项目根据 MIT许可证
