Linux command
ag 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Search
ag [pattern]
Example
ag --python [pattern]
Example
ag -i [pattern]
Example
ag -l [pattern]
Example
ag -Q "[literal string]"
Example
ag -C [3] [pattern]
说明
ag (The Silver Searcher) is a code-searching tool similar to ack but faster. It searches through source code recursively, automatically ignoring files listed in .gitignore and .hgignore, and skipping hidden files and binary files. The tool is optimized for speed, using multiple threads and memory-mapped I/O. It supports Perl-compatible regular expressions and provides colored output with context lines.
参数
- -i, --ignore-case
- Case insensitive search
- -s, --case-sensitive
- Case sensitive search
- -v, --invert-match
- Invert the match
- -w, --word-regexp
- Match whole words only
- -l, --files-with-matches
- Print only file names with matches
- -L, --files-without-matches
- Print file names without matches
- -c, --count
- Print count of matches per file
- -C _n_, --context=_n_
- Print n lines of context
- -A _n_, --after=_n_
- Print n lines after match
- -B _n_, --before=_n_
- Print n lines before match
- -Q, --literal
- Treat pattern as literal string
- --python, --js, --html, etc.
- Search only specific file types
- -g _pattern_
- Search file names matching pattern
- --hidden
- Search hidden files
- -u, --unrestricted
- Search all files (ignore .gitignore)
- -z, --search-zip
- Search inside compressed files
FAQ
What is the ag command used for?
ag (The Silver Searcher) is a code-searching tool similar to ack but faster. It searches through source code recursively, automatically ignoring files listed in .gitignore and .hgignore, and skipping hidden files and binary files. The tool is optimized for speed, using multiple threads and memory-mapped I/O. It supports Perl-compatible regular expressions and provides colored output with context lines.
How do I run a basic ag example?
Run `ag [pattern]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i, --ignore-case do in ag?
Case insensitive search