2025-03-14 21:59:59 -06:00
|
|
|
# ag
|
|
|
|
|
|
|
|
|
|
> The Silver Searcher. Like `ack`, but aims to be faster.
|
2025-04-03 20:36:56 -06:00
|
|
|
> More information: <https://manned.org/ag>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Find files containing "foo", and print the line matches in context:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag foo`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Find files containing "foo" in a specific directory:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag foo {{path/to/directory}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
- Find files containing "foo", but only list the filenames:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag {{[-l|--files-with-matches]}} foo`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-04-03 20:36:56 -06:00
|
|
|
- Find files containing "FOO" case-insensitively, and print only the match, rather than the whole line:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag {{[-i|--ignore-case]}} {{[-o|--only-matching]}} FOO`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Find "foo" in files with a name matching "bar":
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag foo {{[-G|--file-search-regex]}} bar`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Find files whose contents match a regular expression:
|
|
|
|
|
|
|
|
|
|
`ag '{{^ba(r|z)$}}'`
|
|
|
|
|
|
|
|
|
|
- Find files with a name matching "foo":
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`ag {{[-g|--filename-pattern]}} foo`
|