AG(1)
β¨ 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 athttps://github.com/protocool/AckMate--[no]affinityβ sets thread affinity, but only if your platform supports it π§΅ Default istrue.-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,LINESdefaults to2.-B,--before [LINES]β prints lines before each match πΈ If you don't give it a number,LINESdefaults to2.--[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 is1;33.--color-matchβ sets the color codes for the match numbers in results π Default is30;43.--color-pathβ sets the color codes for path names π Default is1;32.--columnβ prints column numbers in results π-C,--context [LINES]β prints lines before and after matches π«§ Default is2.-D,--debugβ outputs a ridiculous amount of debugging info π Not useful unless you're actually debugging, bestie.--depth NUMβ searches up toNUMdirectories deep, and-1means unlimited πͺ Default is25.--[no]filenameβ prints file names π Enabled by default, except when you're searching a single file.-f,--[no]followβ follows symlinks π Default isfalse.-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 π--nogroupskips that and puts the filename at the start of every match line instead.-g PATTERNβ prints the filenames that matchPATTERNποΈ-G,--file-search-regex PATTERNβ only searches files whose names matchPATTERNπ―-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--ignoreso 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 afterNUMmatches βοΈ Default is0, which never skips.--[no]mmapβ toggles memory-mapped I/O π§ Defaults totrueon platforms wheremmap()is faster thanread(). (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.ignorefile π--pager COMMANDβ uses a pager likelessπ Use--nopagerto 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 parsePATTERNas a regular expression, just tries to match it literally π§Ύ-r,--recurseβ recurses into directories when searching π³ Default istrue.-s,--case-sensitiveβ matches case-sensitively π-S,--smart-caseβ matches case-sensitively ifPATTERNhas 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~/.vimrcconfig 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β usesNUMworker threads π§΅ Default is the number of CPU cores, with a max of8.-z,--search-zipβ searches the contents of compressed files ποΈ Right now,gzandxzare supported. This option requires that ag is built withlzmaandzlib.-0,--null,--print0β separates the filenames with\0instead of\nπ§© This letsxargs -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 πβ¨
π¦ where this page comes from
- alpine 3.24: the_silver_searcher-doc 2.2.0-r1 Β· Apache-2.0
- debian bookworm: silversearcher-ag 2.2.0+git20200805-1+b1 Β· Apache-2.0
- debian trixie: silversearcher-ag 2.2.0+git20200805-1.2 Β· Apache-2.0
- epel 9: the_silver_searcher 2.2.0^2020704.5a1c8d8-3.el9 Β· ASL 2.0 and BSD
- fedora 43: the_silver_searcher 2.2.0^2020704.5a1c8d8-14.fc43 Β· Apache-2.0
- fedora 44: the_silver_searcher 2.2.0^2020704.5a1c8d8-15.fc44 Β· Apache-2.0
- nixos 26.05: silver-searcher 2.2.0
- ubuntu jammy: silversearcher-ag 2.2.0+git20200805-1 Β· Apache-2.0
- ubuntu noble: silversearcher-ag 2.2.0+git20200805-1.1 Β· Apache-2.0
- ubuntu questing: silversearcher-ag 2.2.0+git20200805-1.2
- ubuntu resolute: silversearcher-ag 2.2.0+git20200805-1.2build1 Β· Apache-2.0
- ubuntu stonking: silversearcher-ag 2.2.0+git20200805-1.2build1 Β· Apache-2.0
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms