AG(1)

πŸ“¦
version 2.2.0+git20200805 Β· 3 versions
, in alpine 3.24, debian bookworm, debian trixie, epel 9, fedora 43, fedora 44, nixos 26.05, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

ag - The Silver Searcher. Like ack, but faster. πŸ¦‹

🧚 SYNOPSIS 🧚

ag [options] pattern [path ...]

πŸ’– DESCRIPTION πŸ’–

okay so ag recursively searches for PATTERN in PATH πŸ” It's like grep or ack, but it's lowkey faster and it's giving speed ⚑

πŸŽ€ OPTIONS πŸŽ€

  • --ackmate β€” outputs results in a format AckMate can parse 🫢 check it out at https://github.com/protocool/AckMate
  • --[no]affinity β€” sets thread affinity, but only if your platform supports it 🧡 Default is true.
  • -a, --all-types β€” searches all files πŸ’… It doesn't include hidden files, and it doesn't respect any ignore files, so be careful bestie πŸ’€
  • -A, --after [LINES] β€” prints lines after each match ✨ If you don't give it a number, LINES defaults to 2.
  • -B, --before [LINES] β€” prints lines before each match 🌸 If you don't give it a number, LINES defaults to 2.
  • --[no]break β€” prints a newline between matches in different files πŸ“ Enabled by default.
  • -c, --count β€” only prints the number of matches in each file πŸ”’
Note: this counts matches, not matching lines. If you want the number of matching lines, pipe the output to wc -l πŸ™ˆ
  • --[no]color β€” prints color codes in results 🌈 Enabled by default.
  • --color-line-number β€” sets the color codes for line numbers πŸ’œ Default is 1;33.
  • --color-match β€” sets the color codes for the match numbers in results πŸ’œ Default is 30;43.
  • --color-path β€” sets the color codes for path names πŸ’š Default is 1;32.
  • --column β€” prints column numbers in results πŸ“
  • -C, --context [LINES] β€” prints lines before and after matches 🫧 Default is 2.
  • -D, --debug β€” outputs a ridiculous amount of debugging info 😭 Not useful unless you're actually debugging, bestie.
  • --depth NUM β€” searches up to NUM directories deep, and -1 means unlimited πŸͺœ Default is 25.
  • --[no]filename β€” prints file names πŸ“ Enabled by default, except when you're searching a single file.
  • -f, --[no]follow β€” follows symlinks πŸ”— Default is false.
  • -F, --fixed-strings β€” an alias for --literal, so grep users feel at home 🏠
  • --[no]group β€” the default, --group, lumps multiple matches in the same file together under one filename header πŸŽ€ --nogroup skips that and puts the filename at the start of every match line instead.
  • -g PATTERN β€” prints the filenames that match PATTERN πŸ—‚οΈ
  • -G, --file-search-regex PATTERN β€” only searches files whose names match PATTERN 🎯
  • -H, --[no]heading β€” prints filenames above the matching contents πŸ‘‘
  • --hidden β€” searches hidden files πŸ™ˆ This option still obeys ignored files.
  • --ignore PATTERN β€” ignores files and directories whose names match this pattern 🚫 Literal file and directory names work too.
  • --ignore-dir NAME β€” an alias for --ignore so ack users feel seen 🫢
  • -i, --ignore-case β€” matches case-insensitively 🫠
  • -l, --files-with-matches β€” only prints the names of files that have matches, not the matching lines πŸ“ An empty query will print every file that would be searched.
  • -L, --files-without-matches β€” only prints the names of files that don't have matches πŸ™…β€β™€οΈ
  • --list-file-types β€” shows the file types you can use, see FILE TYPES below πŸ¦‹
  • -m, --max-count NUM β€” skips the rest of a file after NUM matches βœ‚οΈ Default is 0, which never skips.
  • --[no]mmap β€” toggles memory-mapped I/O 🧠 Defaults to true on platforms where mmap() is faster than read(). (That's all of them except macOS 🍎)
  • --[no]multiline β€” matches regexes across newlines 🧡 Enabled by default.
  • -n, --norecurse β€” doesn't recurse into directories πŸ›‘
  • --[no]numbers β€” prints line numbers πŸ”’ By default, line numbers are omitted when searching streams.
  • -o, --only-matching β€” prints only the matching part of each line 🎯
  • --one-device β€” when recursing, skips directories that live on other storage devices 🌐 This is how you dodge slow network mounts 🐒 Not supported on every platform, sadly.
  • -p, --path-to-ignore STRING β€” gives a path to a specific .ignore file πŸ“‚
  • --pager COMMAND β€” uses a pager like less πŸ“– Use --nopager to override it. This option is also ignored if the output is piped to another program.
  • --parallel β€” treats the input stream as a search term instead of data to search 🧚 This is meant for tools like GNU parallel. For example:
echo "foo\nbar\nbaz" | parallel "ag {} ."

This runs 3 instances of ag, searching the current directory for "foo", "bar", and "baz" ✨

  • --print-long-lines β€” prints matches on super long lines πŸ“ (anything over 2k characters by default)
  • --passthrough, --passthru β€” when searching a stream, prints all lines, even the ones that don't match 🌊
  • -Q, --literal β€” doesn't parse PATTERN as a regular expression, just tries to match it literally 🧾
  • -r, --recurse β€” recurses into directories when searching 🌳 Default is true.
  • -s, --case-sensitive β€” matches case-sensitively πŸ’Ž
  • -S, --smart-case β€” matches case-sensitively if PATTERN has any uppercase letters, and case-insensitively otherwise 🧠 Enabled by default.
  • --search-binary β€” searches binary files for matches πŸ€–
  • --silent β€” suppresses all log messages, including errors 🀫
  • --stats β€” prints stats like files scanned and time taken πŸ“Š
  • --stats-only β€” prints those same stats and nothing else πŸ“Š
  • -t, --all-text β€” searches all text files πŸ“„ This doesn't include hidden files.
  • -u, --unrestricted β€” searches all files πŸ”“ It ignores .ignore, .gitignore, etc., and searches binary and hidden files as well πŸ’€
  • -U, --skip-vcs-ignores β€” ignores VCS ignore files (.gitignore, .hgignore), but still uses .ignore 🫢
  • -v, --invert-match β€” matches every line that does not contain the pattern πŸ™ƒ
  • -V, --version β€” prints version info 🏷️
  • --vimgrep β€” outputs results in the same form as Vim's :vimgrep /pattern/g πŸ–ŠοΈ Here's a ~/.vimrc config example:
set grepprg=ag\ --vimgrep\ $* set grepformat=%f:%l:%c:%m

Then use :grep to grep for something, and then use :copen, :cn, :cp, etc. to navigate through the matches πŸ¦‹

  • -w, --word-regexp β€” only matches whole words πŸ’¬
  • --workers NUM β€” uses NUM worker threads 🧡 Default is the number of CPU cores, with a max of 8.
  • -z, --search-zip β€” searches the contents of compressed files πŸ—œοΈ Right now, gz and xz are supported. This option requires that ag is built with lzma and zlib.
  • -0, --null, --print0 β€” separates the filenames with \0 instead of \n 🧩 This lets xargs -0 <command> correctly handle filenames with spaces or newlines 🫧

πŸ¦‹ FILE TYPES πŸ¦‹

It's possible to restrict the types of files searched πŸ’… For example, passing --html will search only files with the extensions htm, html, shtml, or xhtml. For a list of supported types, run ag --list-file-types ✨

🌸 IGNORING FILES 🌸

By default, ag ignores files whose names match patterns in .gitignore, .hgignore, or .ignore πŸ™ˆ These files can be anywhere in the directories being searched. Binary files are ignored by default too. Finally, ag looks in $HOME/.agignore for ignore patterns 🏑

If you want to ignore .gitignore and .hgignore but still take .ignore into account, use -U 🫢

Use -t to search all text files, -a to search all files, and -u to search all of them, including hidden files πŸ”“

πŸ’… EXAMPLES πŸ’…

  • ag printf β€” finds matches for "printf" in the current directory πŸ”
  • ag foo /bar/ β€” finds matches for "foo" in the path /bar/ πŸ“‚
  • ag -- --foo β€” finds matches for "--foo" in the current directory 🧠 As with most UNIX command line utilities, -- tells ag that the remaining arguments shouldn't be treated as options, which is a whole mood 🫢

πŸ‘‘ ABOUT πŸ‘‘

ag was originally created by Geoff Greer πŸ’– More information (and the latest release) can be found at http://geoff.greer.fm/ag 🌈

🫢 SEE ALSO 🫢

grep(1) πŸ“


Bestie, that's the whole page, and it was last updated in December 2016 πŸ’œ Go be a AG(1) legend πŸ‘‘βœ¨