2014-05-01 21:23:01 -04:00
|
|
|
# ag
|
|
|
|
|
2023-12-03 19:59:57 +07:00
|
|
|
> The Silver Searcher. Like `ack`, but aims to be faster.
|
2025-03-28 05:26:23 +02:00
|
|
|
> More information: <https://manned.org/ag>.
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2016-05-02 14:33:59 +01:00
|
|
|
- Find files containing "foo", and print the line matches in context:
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2017-10-30 23:48:56 +01:00
|
|
|
`ag {{foo}}`
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2018-10-26 21:29:29 +02:00
|
|
|
- Find files containing "foo" in a specific directory:
|
|
|
|
|
2019-02-08 01:28:43 +01:00
|
|
|
`ag {{foo}} {{path/to/directory}}`
|
2018-10-26 21:29:29 +02:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
- Find files containing "foo", but only list the filenames:
|
2016-02-18 09:58:34 -08:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ag {{[-l|--files-with-matches]}} {{foo}}`
|
2016-05-02 14:33:59 +01:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
- Find files containing "FOO" case-insensitively, and print only the match, rather than the whole line:
|
2016-05-02 14:33:59 +01:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ag {{[-i|--ignore-case]}} {{[-o|--only-matching]}} {{FOO}}`
|
2016-02-18 09:58:34 -08:00
|
|
|
|
2016-01-07 18:31:27 +01:00
|
|
|
- Find "foo" in files with a name matching "bar":
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ag {{foo}} {{[-G|--file-search-regex]}} {{bar}}`
|
2014-05-01 21:23:01 -04:00
|
|
|
|
|
|
|
- Find files whose contents match a regular expression:
|
|
|
|
|
2017-10-31 22:41:52 +01:00
|
|
|
`ag '{{^ba(r|z)$}}'`
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2016-01-07 18:31:27 +01:00
|
|
|
- Find files with a name matching "foo":
|
2014-05-01 21:23:01 -04:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ag {{[-g|--filename-pattern]}} {{foo}}`
|