Update: 2020-12-21
A code searching tool similar to
ack
, with a focus on speed.
brew install the_silver_searcher
ag [options] pattern [path ...]
# 当前目录下搜索 foo 字符串所出现的位置,并且高亮显示
ag foo
# 在 ttt 目录下搜索 foo 字符串
ag foo ttt/
ag
默认支持正则表达式
# 在当前目录下搜索以 google 开头的字符串
ag ^google
按照字面意思来搜索字符串
# 在当前目录下搜索 .rb 字符串
ag -Q .rb
指定文件类型
# 在当前目录下搜索txt文件中包含 以google开头的行
ag ^google -G .txt
仅输出匹配到的内容
# 在当前目录的txt文件中搜索以google开头的内容
ag ^google -o -G .txt
指定忽略的文件夹
# 当前目录忽略lib目录,搜索以google开头的内容
ag ^google -ignore-dir=lib