2014-10-01 23:02:25 +01:00
|
|
|
# ack
|
|
|
|
|
2023-12-03 12:59:57 +00:00
|
|
|
> A search tool like `grep`, optimized for developers.
|
2021-03-24 23:50:01 +00:00
|
|
|
> See also: `rg`, which is much faster.
|
|
|
|
> More information: <https://beyondgrep.com/documentation>.
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Search for files containing a string or regular expression in the current directory recursively:
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
`ack "{{search_pattern}}"`
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Search for a case-insensitive pattern:
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
`ack --ignore-case "{{search_pattern}}"`
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Search for lines matching a pattern, printing [o]nly the matched text and not the rest of the line:
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
`ack -o "{{search_pattern}}"`
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Limit search to files of a specific type:
|
2014-10-01 23:02:25 +01:00
|
|
|
|
2024-04-18 19:38:25 +01:00
|
|
|
`ack --type {{ruby}} "{{search_pattern}}"`
|
2019-03-07 08:23:13 +00:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Do not search in files of a specific type:
|
2020-05-11 09:57:08 +01:00
|
|
|
|
2024-04-18 19:38:25 +01:00
|
|
|
`ack --type no{{ruby}} "{{search_pattern}}"`
|
2020-05-11 09:57:08 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Count the total number of matches found:
|
2020-05-11 09:57:08 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
`ack --count --no-filename "{{search_pattern}}"`
|
2020-05-11 09:57:08 +01:00
|
|
|
|
2021-03-24 23:50:01 +00:00
|
|
|
- Print the file names and the number of matches for each file only:
|
|
|
|
|
|
|
|
`ack --count --files-with-matches "{{search_pattern}}"`
|
|
|
|
|
2021-10-13 07:26:17 +01:00
|
|
|
- List all the values that can be used with `--type`:
|
2019-03-07 08:23:13 +00:00
|
|
|
|
2020-07-16 22:33:06 +01:00
|
|
|
`ack --help-types`
|