UGREP(1)
UGREP(1) β User Commands π
πΈ NAME πΈ
ugrep, ug β file pattern searcher π
β¨ SYNOPSIS β¨
ugrep [OPTIONS] [-i|-j] [-Q|PATTERN] [-e PATTERN] [-N PATTERN] [-f FILE]
[-E|-F|-G|-P|-Z] [-U] [-m [MIN,][MAX]] [--bool [--files|--lines]]
[-r|-R|-1|...|-9|-10|-11|...] [-t TYPES] [-g GLOBS] [--sort[=KEY]]
[-q|-l|-c|-o] [-v] [-n] [-k] [-b] [-A NUM] [-B NUM] [-C NUM] [-y]
[--color[=WHEN]|--colour[=WHEN]] [--pretty] [--pager[=COMMAND]]
[--hexdump|--csv|--json|--xml] [-I] [-z] [--zmax=NUM] [FILE ...]
π¦ DESCRIPTION π¦
Okay so ugrep is out here searching any input files you give it, picking out the files and lines that match one or more patterns β and those patterns can be regular expressions or fixed strings. A pattern can match multiple input lines when the patternβs regular expression matches one or more newlines. An empty pattern matches every line. Every input line that matches at least one of the patterns gets written to standard output. Slay. β¨
The ug command is the interactive-search version, using a .ugrep configuration file in the working directory or, if itβs not found there, in the home directory β see CONFIGURATION. ug is equivalent to ugrep --config --pretty --sort so it loads a configuration file, enhances the terminal output, and sorts files by name.
The ugrep+ and ug+ commands are the same as the ugrep and ug commands, but they also use filters to search pdfs, documents, e-books, and image metadata when the corresponding filter tools are installed. Iconic behavior, honestly. π
A list of matching files is produced with option -l (--files-with-matches). Option -c (--count) counts the number of matching lines. When combined with option -o, it counts the total number of matches. When combined with option -m1 (--min-count=1), it skips files with zero matches. No notes. π
The default pattern syntax is an extended form of the POSIX ERE syntax, same as option -E (--extended-regexp). Try ug --help regex for help with pattern syntax and how to use logical connectives to specify Boolean search queries with option -% (--bool) to match lines and -%% (--bool --files) to match files. Options -F (--fixed-strings), -G (--basic-regexp) and -P (--perl-regexp) specify other pattern syntaxes. We love options. We contain multitudes. π
Option -i (--ignore-case) ignores letter case in patterns. Option -j (--smart-case) enables -i only if the search patterns are specified in lower case.
Fuzzy (approximate) search is specified with option -Z (--fuzzy) with an optional argument to control character insertions, deletions, and/or substitutions. Try ug --help fuzzy for help with fuzzy search. Lowkey magical. π§
Note that pattern . matches any non-newline character. Pattern \n matches a newline character. Multiple lines may be matched with patterns that match one or more newline characters.
The empty pattern "" matches all lines. Other empty-matching patterns do not. For example, the pattern a* will match one or more aβs. Option -Y forces empty matches for compatibility with other grep tools.
Option -f FILE matches patterns specified in FILE.
By default Unicode patterns are matched. Option -U (--ascii or --binary) disables Unicode matching for ASCII and binary pattern matching. Non-Unicode matching is more efficient. Efficient queen behavior. β‘
ugrep accepts input of various encoding formats and normalizes the output to UTF-8. When a UTF byte order mark is present in the input, the input is automatically normalized. An input encoding format may be specified with option --encoding.
If no FILE arguments are specified and standard input is read from a terminal, recursive searches are performed as if -r is specified. To force reading from standard input, specify - as a FILE argument.
Directories specified as FILE arguments are searched without recursing deeper into subdirectories, unless -R, -r, or -2...-9 is specified to search subdirectories recursively (up to the specified depth.)
Option -I (--ignore-binary) ignores binary files. A binary file is a file with non-text content. A file with zero bytes or invalid UTF formatting is considered binary.
Hidden files and directories are ignored in recursive searches. Option -. (--hidden) includes hidden files and directories in recursive searches.
To match the names of files to search and the names of directories to recurse, one or more of the following options may be specified. Option -O specifies one or more filename extensions to match. Option -t specifies one or more file types to search (-t list outputs a list of types.) Option -g specifies a gitignore-style glob pattern to match filenames. Option --ignore-files specifies a file with gitignore-style globs to ignore directories and files. Try ug --help globs for help with filename and directory name matching. See also section GLOBBING.
Compressed files and archives are searched with option -z (--decompress). When used with option --zmax=NUM, searches the contents of compressed files and archives stored within archives up to NUM levels. Unzipping the mysteries of the universe, honestly. π
Output to a terminal for viewing is enhanced with --pretty, which is enabled by default with the ug command.
A query terminal user interface (TUI) is opened with -Q (--query) to interactively specify search patterns and view search results. A PATTERN argument requires -e PATTERN to start the query TUI with the specified pattern.
A terminal output pager is enabled with --pager that accepts an optional COMMAND to view the output.
Customized output is produced with option --format or --replace. Try ug --help format for help with custom formatting of the output. See also section FORMAT. Predefined formats include CSV with option --csv, JSON with option --json, and XML with option --xml. Hexdumps are output with option -X (--hex) or with option --hexdump to customize hexdumps.
A -- signals the end of options; the rest of the parameters are FILE arguments, allowing filenames to begin with a - character.
Long options may start with --no- to disable, when applicable.
ug --help WHAT displays help on options related to WHAT.
π The following options are available: π
-A NUM,--after-context=NUMβ Outputs NUM lines of trailing context after matching lines. It places a--group-separatorbetween contiguous groups of matches. If-ois specified, it outputs the match with context to fit NUM columns after the match or shortens the match. See also options-B,-Cand-y. Trailing context bestie.-a,--textβ Processes a binary file as if it were text. This is equivalent to the--binary-files=textoption. This option might output binary garbage to the terminal, which can have problematic consequences if the terminal driver interprets some of it as terminal commands. Be careful with that one, fr fr.--all,-@β Searches all files except hidden files: it cancels previous file and directory search restrictions and cancels--ignore-binaryand--ignore-fileswhen specified. Restrictions specified after this option, i.e. to the right, are still applied. For example,-@Isearches all non-binary files and-@.searches all files including hidden files. Note that hidden files and directories are never searched, unless option-.or--hiddenis specified. We love a cleanup moment.--and [-e] PATTERNβ Specifies additional PATTERN that must match. Additional-e PATTERNfollowing this option is considered an alternative pattern to match, i.e. each-eis interpreted as an OR pattern enclosed within the AND. For example,-e A -e B --and -e C -e Dmatches lines with (AorB) and (CorD). Note that multiple-e PATTERNare alternations that bind more tightly together than--and. Option--statsdisplays the search patterns applied. See also options--not,--andnot,--bool,--filesand--lines. Boolean drama, but make it useful.--andnot [-e] PATTERNβ Combines--and --not. See also options--and,--notand--bool.-B NUM,--before-context=NUMβ Outputs NUM lines of leading context before matching lines. It places a--group-separatorbetween contiguous groups of matches. If-ois specified, it outputs the match with context to fit NUM columns before the match or shortens the match. See also options-A,-Cand-y. Leading context, coming through.-b,--byte-offsetβ The offset in bytes of a pattern match is displayed in front of the respective matched line. When-uor--ungroupis specified, it displays the offset for each pattern matched on the same line. Byte offsets are exact for ASCII, UTF-8 and raw binary input. Otherwise, the offset in the UTF-8-normalized input is displayed.--binary-files=TYPEβ Controls searching and reporting pattern matches in binary files. TYPE can bebinary,without-match,text,hexandwith-hex. The default isbinaryto search binary files and to report a match without displaying the match.without-matchignores binary matches.texttreats all binary files as text, which might output binary garbage to the terminal, which can have problematic consequences if the terminal driver interprets some of it as commands.hexreports all matches in hexadecimal.with-hexonly reports binary matches in hexadecimal, leaving text matches alone. Files having NUL (zero) bytes are binary and files with invalid UTF encoding are binary unless option-Uor--asciior--binaryis specified. Short options are-a,-I,-W,-X. Thatβs the binary-files breakdown, periodt.--bool,-%,-%%β okay bestie, this is the Boolean query era π . A Boolean query pattern is built out ofAND,OR,NOToperators plus grouping with(and). Spacing between subpatterns does the same job asAND, a|does the same job asOR, and a-does the same job asNOT. Heads up: theORoperator binds more tightly thanAND. So--bool 'A|B C|D'matches lines with (AorB) and (CorD), and--bool 'A -B'matches lines withAand notB. The operatorsAND,OR,NOTneed proper spacing β like, actual spaces, she's not flexible about this. For example,--bool 'A OR B AND C OR D'matches lines with (AorB) and (CorD), and--bool 'A AND NOT B'matches lines withAwithoutB. Quoted subpatterns get matched literally as strings β so--bool 'A "AND"|"OR"'matches lines withAand also eitherANDorOR. Parentheses are for grouping:--bool '(A B)|C'matches lines withAandB, or lines withC. Note that all subpatterns in a Boolean query pattern are regular expressions, unless-Fis specified. Options-E,-F,-G,-Pand-Zcan be combined with--boolto match subpatterns as strings or regular expressions (-Eis the default). This option does not apply to-f FILEpatterns. The double short option-%%enables options--bool --files. Option--statsdisplays the Boolean search patterns applied. See also options--and,--andnot,--not,--filesand--lines.--breakβ adds a line break between results from different files π. This option is enabled by--heading.-C NUM,--context=NUMβ outputsNUMlines of leading and trailing context surrounding each matching line. Drops a--group-separatorbetween contiguous groups of matches. If-ois specified, it outputs the match with context to fitNUMcolumns before and after the match, or shortens the match. See also options-A,-Band-y.-c,--countβ only a count of selected lines gets written to standard output β¨. When-oor-uis specified, it counts the number of patterns matched. When-vis specified, it counts the number of non-matching lines. When-m1,(with a comma, or--min-count=1) is specified, it counts only matching files without outputting zero matches.--color[=WHEN],--colour[=WHEN]β marks up the matching text with the colors specified with option--colorsor theGREP_COLORorGREP_COLORSenvironment variable π.WHENcan benever,always, orauto, whereautomarks up matches only when output on a terminal. The default isauto.--colors=COLORS,--colours=COLORSβ usesCOLORSto mark up text π¨.COLORSis a colon-separated list of one or more parameters:sl=(selected line),cx=(context line),mt=(matched text),ms=(match selected),mc=(match context),fn=(file name),ln=(line number),cn=(column number),bn=(byte offset),se=(separator),qp=(TUI prompt),qe=(TUI errors),qr=(TUI regex),qm=(TUI regex meta characters),ql=(TUI regex lists and literals),qb=(TUI regex braces). Parameter values are ANSI SGR color codes, ork(black),r(red),g(green),y(yellow),b(blue),m(magenta),c(cyan),w(white), or leave it empty for no color. Upper case specifies background colors. A+qualifies a color as bright. A foreground and a background color may be combined with font propertiesn(normal),f(faint),h(highlight),i(invert),u(underline). Parameterhlenables file name hyperlinks. Parameterrvreverses thesl=andcx=parameters when option-vis specified. Selectively overridesGREP_COLORS. Legacy grep single parameter codes may be specified, for example--colors='7;32'or--colors=igto setms(match selected). iconic, honestly.--config[=FILE],---[FILE]β use configurationFILEποΈ. The defaultFILEis.ugrep. The working directory is checked first forFILE, then the home directory. The options specified in the configurationFILEare parsed first, followed by the remaining options specified on the command line. Theugcommand automatically loads a.ugrepconfiguration file when present, unless--config=FILEor--no-configis specified.--no-configβ do not automatically load the default.ugrepconfiguration file π ββοΈ.--no-confirmβ do not confirm actions in-Qquery TUI. The default is confirm.--cppβ output file matches in C++ π». See also options--formatand-u.--csvβ output file matches in CSV π. When-H,-n,-k, or-bis specified, additional values are output. See also options--formatand-u.-D ACTION,--devices=ACTIONβ if an input file is a device, FIFO or socket, useACTIONto process it π. WhenACTIONisskip, devices are ignored. WhenACTIONisread, devices are read just as if they were ordinary files. The defaultACTIONisskip, except for devices specified as arguments on the command line, which can be explicitly skipped with-Dskip.-d ACTION,--directories=ACTIONβ if an input file is a directory, useACTIONto process it π. WhenACTIONisread, warn when directories are read as input. WhenACTIONisrecurse, read all files under each directory, recursively, following symbolic links only if they are on the command line β this is equivalent to the-roption. WhenACTIONisdereference-recurse, read all files under each directory, recursively, following symbolic links β this is equivalent to the-Roption. When no files or directories are specified on the command line,ACTIONdefaults torecurseor option-r.--delay=DELAYβ sets the default-Qkey response delay β±οΈ. Default is3for 300ms.--depth=[MIN,][MAX],-1,-2,-3, β¦-9,-10,-11, β¦ β restricts recursive searches fromMINtoMAXdirectory levels deep, where-1(--depth=1) searches the specified path without recursing into subdirectories. The short forms-3 -5,-3-5and-3,5search 3 to 5 levels deep. Enables-rif-Ror-ris not specified.--dotallβ dot.in regular expressions matches anything, including newline π«§.
Note that .* matches all input and should not be used. Like, genuinely, don't. π
-E,--extended-regexpβ interpret patterns as extended regular expressions (EREs). This is the default β.-e PATTERN,--regexp=PATTERNβ specify aPATTERNto search the input. An input line is selected if it matches any of the specified patterns. This option is useful when multiple-eoptions are used to specify multiple patterns, or when a pattern starts with a dash (-), or to specify a pattern after option-for after theFILEarguments π.--encoding=ENCODINGβ the encoding format of the input π. The defaultENCODINGis binary or UTF-8 which are treated the same. Therefore,--encoding=binaryhas no effect. Contrast this with option-Uor--asciior--binarythat specifies raw binaryPATTERNmatching.ENCODINGcan be:binary,ASCII,UTF-8,UTF-16,UTF-16BE,UTF-16LE,UTF-32,UTF-32BE,UTF-32LE,LATIN1,ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,ISO-8859-9,ISO-8859-10,ISO-8859-11,ISO-8859-13,ISO-8859-14,ISO-8859-15,ISO-8859-16,MAC,MACROMAN,EBCDIC,CP437,CP850,CP858,CP1250,CP1251,CP1252,CP1253,CP1254,CP1255,CP1256,CP1257,CP1258,KOI8-R,KOI8-U,KOI8-RU,null-data. The way that list just goes off, she really said "every encoding" and meant it π.--exclude=GLOBβ excludes files whose name matchesGLOB, same as-g ^GLOBπ«.GLOBcan use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. WhenGLOBcontains a/, full pathnames are matched. Otherwise basenames are matched. WhenGLOBends with a/, directories are excluded as if--exclude-diris specified. Otherwise files are excluded. Note that--excludepatterns take priority over--includepatterns.GLOBshould be quoted to prevent shell globbing. This option may be repeated.--exclude-dir=GLOBβ excludes directories whose name matchesGLOBfrom recursive searches, same as-g ^GLOB/π.GLOBmay use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. WhenGLOBcontains a/, full pathnames are matched. Otherwise basenames are matched. Note that--exclude-dirpatterns take priority over--include-dirpatterns.GLOBshould be quoted to prevent shell globbing. This option may be repeated.--exclude-from=FILEβ reads the globs fromFILEand skips files and directories whose name matches one or more globs π. A glob may use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. When a glob contains a/, full pathnames are matched. Otherwise basenames are matched. When a glob ends with a/, directories are excluded as if--exclude-diris specified. Otherwise files are excluded. A glob starting with a!overrides previously-specified exclusions by including matching files. Lines starting with a#inFILEare ignored. WhenFILEis a-, standard input is read. This option may be repeated. See also related option--ignore-filesfor subdirectory-specific exclusions.--exclude-fs=MOUNTSβ excludes file systems specified byMOUNTSfrom recursive searches π½.MOUNTSis a comma-separated list of mount points or pathnames to directories. WhenMOUNTSis not specified, it only descends into the file systems associated with the specified file and directory search targets, i.e. it excludes all other file systems. Note that--exclude-fs=MOUNTStake priority over--include-fs=MOUNTS. This option may be repeated.-F,--fixed-stringsβ interpret pattern as a set of fixed strings, separated by newlines, any of which is to be matched π§΅. This makesugrepbehave asfgrep. If aPATTERNis specified, or-e PATTERNor-N PATTERN, then this option has no effect on-f FILEpatterns β to allow-f FILEpatterns to narrow or widen the scope of thePATTERNsearch.-f FILE,--file=FILEβ bestie, this is your pattern plug π. It reads patterns fromFILE, one per line (newline-separated, obvi). White space inside patterns is significant β do not sleep on your spaces, they matter. Empty lines inFILEare just ignored, they're not the vibe. IfFILEdoesn't exist, theGREP_PATHenvironment variable gets used as the path toFILE. And if that fails? It goes looking forFILEin/usr/local/share/ugrep/patterns. WhenFILEis a-, standard input is read. Empty files contain no patterns β which means nothing is matched, iykyk. This option may be repeated π--files,-%%β Boolean file matching mode, aka the opposite of--lines. When you combine it with option--bool, it matches a file if all Boolean conditions are satisfied. Example era:--bool --files 'A B|C -D'matches a file if some lines matchA, and some lines match eitherBorC, and no line matchesD. See also options--and,--andnot,--not,--booland--lines. The double short option-%%enables options--bool --files. Two percent signs, absolutely iconic π--filter=COMMANDSβ run your files through the specifiedCOMMANDSfirst, before searching.COMMANDSis a comma-separated list ofexts:command arguments, whereextsis a comma-separated list of filename extensions andcommandis a filter utility. Files matching one ofextsget filtered. A*matches any file. The specifiedcommandmay include arguments separated by spaces. An argument may be quoted to include spacing, commas or a%. A%argument expands into the pathname to search. For example,--filter='pdf:pdftotext % -'searches PDF files π₯. The%expands into a-when searching standard input. When a%is not specified, the filter command should read from standard input and write to standard output. Option--label=.extmay be used to specify extensionextwhen searching standard input. Note thatextsfilename extension matching is case insensitive. This option may be repeated β¨--filter-magic-label=[+]LABEL:MAGICβ associateLABELwith files whose signature "magic bytes" match theMAGICregex pattern πͺ. Only files that have no filename extension are labeled, unless+LABELis specified. WhenLABELmatches an extension specified in--filter=COMMANDS, the corresponding command is invoked. This option may be repeated.--format=FORMATβ outputFORMAT-formatted matches, so you can make your output all cute and custom π. For example--format='%f:%n:%O%~'outputs matching lines%Owith filename%fand line number%nfollowed by a newline%~. If-Pis specified,FORMATmay include%1to%9,%[NUM]#and%[NAME]#to output group captures. A%%outputs%. Seeugrep --help formatandman ugrepsection FORMAT for details. When option-ois specified, option-uis also enabled. Context options-A,-B,-Cand-yare ignored β yeah they just get left on read π--free-spaceβ spacing (blanks and tabs) in regular expressions is ignored. She's breezy, she's chill πΈ--from=FILEβ read additional pathnames of files to search fromFILE. WhenFILEis a-, standard input is read. This option is useful withfind ... -print | ugrep --from=- ...to search specific files. Slay, pipeline queen π-G,--basic-regexpβ interpret patterns as basic regular expressions (BREs). Classic, retro, lowkey vintage.-g GLOBS,--glob=GLOBS,--iglob=GLOBSβ only search files whose name matches the specified comma-separated list ofGLOBS, same as--include='glob'for eachglobinGLOBS. When aglobis preceded by a!or a^, skip files whose name matchesglob, same as--exclude='glob'. Whenglobcontains a/, full pathnames are matched and option-ris enabled to recurse into directories if-d,-ror-Ris not already specified. Otherwise basenames are matched. Whenglobends with a/, directories are matched, same as--include-dir='glob'and--exclude-dir='glob'. A leading./or just/matches the working directory. Option--iglob=GLOBSperforms case-insensitive name matching. This option may be repeated and may be combined with options-M,-Oand-t. For more details, seeugrep --help globsandman ugrepsection GLOBBING for details π¦--glob-ignore-caseβ perform case-insensitive glob matching in general. She does not care about your capital letters π--group-separator[=SEP]β useSEPas a group separator for context options-A,-Band-C. The default is a double hyphen (--). Aesthetic divider energy π--no-group-separatorβ removes the group separator line from the output for context options-A,-Band-C. Clean girl aesthetic, no dividers π-H,--with-filenameβ always print the filename with output lines. This is the default when there is more than one file to search. Name and shame, respectfully π«Ά-h,--no-filenameβ never print filenames with output lines. This is the default when there is only one file (or only standard input) to search. She's mysterious, no name needed.--heading,-+β group matches per file. Adds a heading and a line break between results from different files. This option is enabled by--prettywhen the output is sent to the terminal. Organized queen behavior β¨--help [WHAT],-? [WHAT]β display a help message on options related toWHATwhen specified. In addition,--help regexdisplays an overview of regular expressions,--help globsdisplays an overview of glob syntax and conventions,--help fuzzydisplays details of fuzzy search, and--help formatdisplays a list of option--format=FORMATfields. When in doubt, ask for help bestie π--hexdump[=[1-8][a][bch][A[NUM]][B[NUM]][C[NUM]]]β output matches in 1 to 8 columns of 8 hexadecimal octets π₯. The default is 2 columns or 16 octets per line. Argumentaoutputs a*for all hex lines that are identical to the previous hex line,bremoves all space breaks,cremoves the character column,hremoves hex spacing,Aincludes up toNUMhex lines after a match,Bincludes up toNUMhex lines before a match andCincludes up toNUMhex lines before and after a match. ArgumentsA,BandCare the same as options-A,-Band-Cwhen used with--hexdump. See also options-U,-Wand-X. Hexadecimal hex girl fall π--hidden,-.β search hidden files and directories (enabled by default in grep compatibility mode). Not me digging up the hidden files π--hyperlink[=[PREFIX][+]]β hyperlinks are enabled for file names when colors are enabled. Same as--colors=hl. WhenPREFIXis specified, replacesfile://withPREFIX://in the hyperlink. A+includes the line number in the hyperlink and when option-kis specified, the column number. Clickable, gorgeous, main character energy π-I,--ignore-binaryβ ignore matches in binary files. This option is equivalent to the--binary-files=without-matchoption. Files having NUL (zero) bytes are binary. Also files with invalid UTF encoding are binary unless option-Uor--asciior--binaryis specified. Binary files? Not invited to the function π-i,--ignore-caseβ perform case insensitive matching. By default, ugrep is case sensitive. Turn on the chill mode π--ignore-files[=FILE]β ignore files and directories matching the globs in eachFILEthat is encountered in recursive searches. The defaultFILEis.gitignoreπ . Matching files and directories located in the directory of theFILEand in subdirectories are ignored. WhenFILEis a full pathname,FILEis read ahead of the recursive search and globs are globally applied to ignore files and directories. WhenFILEis a-, standard input is read. Globbing is the same as for--exclude-from=FILE, except that--ignore-filesexcludes files and also directories when globs match. This option may be repeated.--no-ignore-filesβ do not ignore files, i.e. cancel--ignore-fileswhen specified. Never mind, we're looking at everything bestie π--include=GLOBβ only search files whose name matchesGLOB, same as-g GLOB.GLOBmay use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. WhenGLOBcontains a/, full pathnames are matched and option-ris enabled to recurse into directories if-d,-ror-Ris not already specified. Otherwise basenames are matched. WhenGLOBends with a/, directories are included as if--include-diris specified. Otherwise files are included. Note that--excludepatterns take priority over--includepatterns β rude but true π.GLOBshould be quoted to prevent shell globbing. This option may be repeated β¨--include-dir=GLOBβ only directories whose name matchesGLOBare included in recursive searches, same as-g GLOB/.GLOBmay use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. WhenGLOBcontains a/, full pathnames are matched and option-ris enabled to recurse into directories if-d,-ror-Ris not already specified. Otherwise basenames are matched. Note that--exclude-dirpatterns take priority over--include-dirpatterns.GLOBshould be quoted to prevent shell globbing. This option may be repeated π¦--include-from=FILEβ read the globs fromFILEand search only files and directories whose name matches one or more globs. A glob may use**,*,?, and[...]as wildcards and\to quote a wildcard or backslash character literally. When a glob contains a/, full pathnames are matched. Otherwise basenames are matched. When a glob ends with a/, directories are included as if--include-diris specified. Otherwise files are included. A glob starting with a!overrides previously-specified inclusions by excluding matching files. Lines starting with a#and empty lines inFILEare ignored. WhenFILEis a-, standard input is read. This option may be repeated π--include-fs=MOUNTSβ only file systems specified byMOUNTSare included in recursive searches.MOUNTSis a comma-separated list of mount points or pathnames to directories. WhenMOUNTSis not specified, restricts recursive searches to the file system of the working directory, same as--include-fs=.(dot). Note that--exclude-fs=MOUNTStake priority over--include-fs=MOUNTS. This option may be repeated π§--indexβ the fast index-based recursive search era π this option assumes (but does not require, no pressure bestie) that your files are indexed withugrep-indexer. It also turns on option-ror--recursivefor you, iconic behaviour honestly. It skips indexed non-matching files, archives and compressed files. Big acceleration may happen on cold (not file-cached) and large file systems, or any file system that's slow to search β literally so satisfying. Heads up though: the start-up time to search may be increased when you specify complex search patterns that contain large Unicode character classes combined with*or+repeats, and those should be avoided. Option-Uor--asciior--binaryimproves performance. Option--statsdisplays an index search report. π«Ά-J NUM,--jobs=NUMβ specifies the number of threads spawned to search files. By default an optimum number of threads is spawned to search files simultaneously (the computer is doing its little multitasking slay β¨).-J1disables threading: files are searched in the same order as specified. Deterministic queen behaviour π-j,--smart-caseβ perform case insensitive matching, unless a pattern is specified with a literal upper case letter. So if you type a capital, it takes you seriously. Smart fr π§--jsonβ output file matches in JSON. When-H,-n,-k, or-bis specified, additional values are output. See also options--formatand-u. Machine-readable realness π-K [MIN,][MAX],--range=[MIN,][MAX],--min-line=MIN,--max-line=MAXβ start searching at line MIN, stop reading input after line MAX. Slice out exactly the lines you want, no cap π-k,--column-numberβ the column number of a pattern match is displayed in front of the respective matched line, starting at column 1. Tabs are expanded in counting columns, see also option--tabs. So you know exactly where the hit landed π-L,--files-without-matchβ only the names of files not containing selected lines are written to standard output. Pathnames are listed once per file searched. If the standard input is searched, the string(standard input)is written. The anti-hype list, we love a contrarian π-l,--files-with-matchesβ only the names of files containing selected lines are written to standard output. Pathnames are listed once per file searched. If the standard input is searched, the string(standard input)is written. Stop reading input upon the first match. Efficient icon behaviour β‘--label=LABELβ displays the LABEL value when input is read from standard input where a file name would normally be printed in the output. Associates a filename extension with standard input when LABEL has a suffix. The default value is(standard input). Give your stdin a little name tag π·οΈ--line-bufferedβ force output to be line buffered instead of block buffered. For when you need your output to arrive immediately, main character energy π--linesβ boolean line matching mode for option--bool, the default mode.-M MAGIC,--file-magic=MAGICβ only search files matching the magic signature pattern MAGIC. The signature "magic bytes" at the start of a file are compared to the MAGIC regex pattern. When matching, the file will be searched. When MAGIC is preceded by a!or a^, skip files with matching MAGIC signatures. This option may be repeated and may be combined with options-Oand-t. Warning bestie: every file on the search path is read, making recursive searches potentially more expensive π¬-m [MIN,][MAX],--min-count=MIN,--max-count=MAXβ require MIN matches, stop reading input upon MAX matches. Output MIN to MAX matches. For example,-m1outputs the first match and-cm1,(with a comma) counts nonzero matches. When-uor--ungroupis specified, each individual match counts. See also option-K. Quota queen π--matchβ match all lines. Same as specifying an empty pattern to search. Everything. All of it. πΈ--max-files=NUMβ restrict the number of files matched to NUM. Note that--sortor-J1may be specified to produce replicable results. If--sortis specified, then the number of threads spawned is limited to NUM.--max-size=MAXβ only search files whose physical size does not exceed MAX bytes. Suffix MAX withkb,mb,gb,tbfor kilo, mega, giga, or terabytes. Little files only pls π--min-size=MINβ only search files whose physical size equals or exceeds MIN bytes. Suffix MIN withkb,mb,gb,tbfor kilo, mega, giga, or terabytes. Big files only, no crumbs π--mmap[=MAX]β use memory maps to search files. By default, memory maps are used under certain conditions to improve performance. When MAX is specified, use up to MAX mmap memory per thread. Memory map slay π§-N PATTERN,--neg-regexp=PATTERNβ specify a negative PATTERN to reject specific-ePATTERN matches with a counter pattern. Note that longer patterns take precedence over shorter patterns, i.e. a negative pattern must be of the same length or longer to reject matching patterns. Option-Ncannot be specified with-P. This option may be repeated. It's giving veto power π-n,--line-numberβ each output line is preceded by its relative line number in the file, starting at line 1. The line number counter is reset for each file processed. Numbered like a lil playlist π΅--not [-e] PATTERNβ specifies that PATTERN should not match. Note that-e A --not -e Bmatches lines withAor lines without aB. To match lines withAthat have noB, specify-e A --andnot -e B. Option--statsdisplays the search patterns applied. See also options--and,--andnot,--bool,--filesand--lines. Logic gates but make it fashion π¦--null,-0β output a zero byte after the file name. This option can be used with commands such asfind -print0andxargs -0to process arbitrary file names, even those that contain newlines. See also options-Hor--with-filenameand--null-data. Newline-proof filenames, we stan π--null-data,-00β input and output are treated as sequences of lines with each line terminated by a zero byte instead of a newline; effectively swaps NUL with LF in the input and the output. When combined with option--encoding=ENCODING, output each line terminated by a zero byte without affecting the input specified as per ENCODING. Instead of option--null-data, option--encoding=null-datatreats the input as a sequence of lines terminated by a zero byte without affecting the output. Option--null-datais not compatible with UTF-16/32 input. Since ugrep matches multiple lines when patterns are specified containing a newline\nor\R, this option is not required for multi-line matching. See also options--encodingand--null. Zero byte era π«Ά-O EXTENSIONS,--file-extension=EXTENSIONSβ only search files whose filename extensions match the specified comma-separated list of EXTENSIONS, same as-g '*.ext'for eachextin EXTENSIONS. When anextis preceded by a!or a^, skip files whose filename extensions matchesext, same as-g '^*.ext'. This option may be repeated and may be combined with options-g,-Mand-t. Filter by vibe of file π-o,--only-matchingβ only the matching part of a pattern match is output. When-A,-Bor-Cis specified, fits the match and its context on a line within the specified number of columns. Just the good part, nothing else β¨--only-line-numberβ only the line number of a matching line is output. The line number counter is reset for each file processed.-P,--perl-regexpβ interpret PATTERN as a Perl regular expression using PCRE2. Note that Perl pattern matching differs from the default grep POSIX pattern matching. Fancy regex bestie, different rules π-p,--no-dereferenceβ if-Ror-ris specified, do not follow symbolic links, even when symbolic links are specified on the command line. Links stay put, respectfully π--pager[=COMMAND]β when output is sent to the terminal, uses COMMAND to page through the output. COMMAND defaults to environment variablePAGERwhen defined orless. Enables--headingand--line-buffered. Scrollable slay π--pretty[=WHEN]β when output is sent to the terminal, enables options--color,--heading,-n,--sort,--treeand-Twhen not explicitly disabled. WHEN can benever,always, orauto. The default isauto. Glow-up mode activated π-Q[=DELAY],--query[=DELAY]β query mode: start a TUI to perform interactive searches. This mode requires an ANSI capable terminal. An optional DELAY argument may be specified to reduce or increase the response time to execute searches after the last key press, in increments of 100ms, where the default is 3 (300ms delay). No whitespace may be given between-Qand its argument DELAY. Initial patterns may be specified with-e PATTERN, i.e. a PATTERN argument requires option-e. Press F1 or CTRL+Z to view the help screen. Press F2 or CTRL+Y to invoke a command to view or edit the file shown at the top of the screen. This command can be specified with option--viewand defaults to environment variablePAGERwhen defined, orVISUALorEDITOR. Press TAB or SHIFT+TAB to navigate directories and to select a file to search. Press ENTER to select lines to output. Press ALT+l for option-lto list files, ALT+n for-n, etc. Non-option commands include ALT+] to increase context and ALT+} to increase fuzzyness. If ALT or OPTION keys are not available, then press CTRL+O + KEY to switch optionKEY, or press F1 or CTRL+Z for help and press KEY. See also options--no-confirm,--delay,--splitand--view. Interactive searching is literally the moment π-q,--quiet,--silentβ quiet mode: suppress all output. Only search a file until a match has been found. Silent but deadly (in a cute way) π€«-R,--dereference-recursiveβ recursively read all files under each directory, following symbolic links to files and directories, unlike-r. Full send into every link π₯-r,--recursiveβ recursively read all files under each directory, following symbolic links only if they are on the command line. Note that when no FILE arguments are specified and input is read from a terminal, recursive searches are performed as if-ris specified. The classic π«Ά--replace=FORMATβ replace matching patterns in the output by FORMAT with%fields. If-Pis specified, FORMAT may include%1to%9,%[NUM]#and%[NAME]#to output group captures. A%%outputs%and%~outputs a newline. See also option--format,ugrep --help formatandman ugrepsection FORMAT for details. Make the output yours β¨-S,--dereference-filesβ when-ris specified, follow symbolic links to files, but not to directories. The default is not to follow symbolic links. Half-way dereference, we love a compromise π-s,--no-messagesβ silent mode, bestie π nonexistent files and unreadable files just get ignored, and their error messages and warnings are suppressed too. Like, no drama, no yelling.--save-config[=FILE] [OPTIONS]β saves a configurationFILEthat includesOPTIONS. If you first loaded it with--config=FILE, thenFILEgets updated. The defaultFILEis.ugrep, which theugcommand loads automatically β¨. WhenFILEis-, it writes the configuration to standard output instead. Heads up: only part of theOPTIONSget saved β specifically the ones that won't make searches fail when combined with other options. You can add extra options by editing the saved configuration file yourself. And a config file can be modified by adding one or moreconfig=FILEto include configuration files, but recursive configuration file inclusion is not permitted π (yes, it will get mad).--separator[=SEP],--context-separator=SEPβ usesSEPas the field separator between the file name, line number, column number, byte offset and the matched line. The default separator is a colon (:) β and a bar (|) for multi-line pattern matches, plus a dash (-) for context lines. See also--group-separatorπ.--splitβ splits the-Qquery TUI screen on startup. That's it, that's the whole vibe π¦.--sort[=KEY]β displays matching files in the order you specify withKEYin recursive searches. Normally theugcommand sorts by name, whereas theugrepbatch command shows matches in no particular order β all in the name of performance, periodt. The sortKEYvalues are:nameβ sort by pathname (this is the default)bestβ sort by best match, works with option-Z(ngl this requires two passes over your files, so it's expensive π)sizeβ sort by file sizeusedβ sort by last access timechangedβ sort by last modification timecreatedβ sort by creation time
Want it backwards? Say less β rname, rbest, rsize, rused, rchanged, or rcreated reverse the sorting. Archive contents are not sorted. Subdirectories are sorted and displayed after the matching files. And FILE arguments get searched in the same order you specified them πΈ.
--statsβ outputs statistics on the number of files and directories searched, plus the inclusion and exclusion constraints that were applied. Receipts, basically π§Ύβ¨.-T,--initial-tabβ adds a tab space to separate the file name, line number, column number and byte offset from the matched line. Clean columns, immaculate alignment π-t TYPES,--file-type=TYPESβ search only files associated withTYPES, which is a comma-separated list of file types. Each file type maps to a set of filename extensions passed to option-Oand filenames passed to option-g. For capitalized file types, the search expands to include files with matching file signature magic bytes, as if you'd passed them to option-Mπ₯. If a type is preceded by a!or a^, it excludes files of that type. Specifying just the initial part of a type name is enough when the choice is unambiguous. This option may be repeated β»οΈ. The possible file types are (and-tlistdisplays the list):actionscript,ada,adoc,asm,asp,aspx,autoconf,automake,awk,Awk,basic,batch,bison,c,c++,clojure,cpp,csharp,css,csv,dart,Dart,delphi,elisp,elixir,erlang,fortran,gif,Gif,go,groovy,gsp,haskell,html,jade,java,jpeg,Jpeg,js,json,jsp,julia,kotlin,less,lex,lisp,lua,m4,make,markdown,matlab,node,Node,objc,objc++,ocaml,parrot,pascal,pdf,Pdf,perl,Perl,php,Php,png,Png,prolog,python,Python,r,rpm,Rpm,rst,rtf,Rtf,ruby,Ruby,rust,scala,scheme,seed7,shell,Shell,smalltalk,sql,svg,swift,tcl,tex,text,tiff,Tiff,tt,typescript,verilog,vhdl,vim,xml,Xml,yacc,yaml,zigπ.--tabs[=NUM]β sets the tab size toNUMso tabs get expanded for option-k.NUMcan be1(no expansion at all),2,4, or8. The default size is8π.--tag[=TAG[,END]]β disables colors so matches get marked up withTAGinstead.ENDmarks the end of a match if you specify it, otherwiseTAGdoes both ends. The default is___β¨.--tree,-^β outputs directories with matching files in a tree-like format π³, for option-cor--count,-lor--files-with-matches, and-Lor--files-without-match. This option is enabled by--prettywhen the output is sent to the terminal.-U,--ascii,--binaryβ disables Unicode matching, giving you ASCII and binary matching instead.PATTERNmatches bytes now. For example,-U '\xa3'matches byteA3(hex) instead of the Unicode code pointU+00A3represented by the UTF-8 sequenceC2 A3. And important: input is not flagged as "binary" just for having invalid UTF β only for having NUL (zero) bytes π.-u,--ungroupβ do not group multiple pattern matches on the same matched line. Output the matched line again for each additional pattern match. Same line, over and over, main character energy π«Ά.-V,--versionβ displays the version with linked libraries and exits. Bye π-v,--invert-matchβ selected lines are the ones that do not match any of the specified patterns. Swapped the vibe check π.--view[=[+]COMMAND]β useCOMMANDto view/edit a file in the-Qquery TUI by pressing Ctrl+Y. If you put a+in front,+COMMANDwaits for a key press afterCOMMANDterminates π¦.-W,--with-hexβ outputs binary matches in hexadecimal, but leaves text matches alone. Equivalent to the--binary-files=with-hexoption. To omit the matching line from the hex output, use both options-Wand--hexdumptogether. See also option-Uπ₯.-w,--word-regexpβ thePATTERNis searched for as a word, so the matching text is preceded by a non-word character and followed by a non-word character. Word-like characters are Unicode letters, digits and connector punctuations such as underscore π .--width[=NUM]β truncates the output toNUMvisible characters per line. If you don't giveNUM, the width of the terminal window is used. Small caveat: double-width characters in the output may result in wider lines than you asked for π.-X,--hexβ outputs matches and matching lines in hexadecimal. Equivalent to the--binary-files=hexoption. To omit the matching line from the hex output, use option--hexdump. See also option-Uβ.-x,--line-regexpβ selects only those matches that exactly match the whole line, as if the patterns were surrounded by^and$π―.--xmlβ outputs file matches in XML. When-H,-n,-k, or-bis specified, additional values are output. See also options--formatand-uπ§.-Y,--emptyβ empty-matching patterns match all lines. Normally, empty matches are not output, unless a pattern starts with^or ends with$. With this option, empty-matching patterns such asx*y?,x*y*z*, andx*(y?|z)match all lines β not just the pattern you expected π. This option is enabled by default in grep compatibility mode; specify option--no-emptyto prevent matching all lines.-y,--any-line,--passthruβ every line is output (passthru). Non-matching lines are output as context with a-separator. See also options-A,-Band-Cπ.-Z[best][+-~][MAX],--fuzzy[=[best][+-~][MAX]]β fuzzy mode, bestie: report approximate pattern matches withinMAXerrors π«. The default is-Z1: one deletion, insertion or substitution is allowed. If+,-and/or~is specified, then+allows insertions,-allows deletions and~allows substitutions. For example,-Z+~3allows up to three insertions or substitutions, but no deletions. Ifbestis specified, then only the best matching lines are output with the lowest cost per file. Option-Zbestrequires two passes over a file and cannot be used with standard input or Boolean queries π. Option--sort=bestorders matching files by best match. The first character of an approximate match always matches a character at the beginning of the pattern β to fuzzy match the first character, replace it with a.or.?. Option-Uapplies fuzzy matching to ASCII and bytes instead of Unicode text. And β οΈ no whitespace may be given between-Zand its argument.-z,--decompressβ search compressed files and archives ποΈ. Archives (.cpio,.pax,.tar) and compressed archives (e.g..zip,.7z,.taz,.tgz,.tpz,.tbz,.tbz2,.tb2,.tz2,.tlz,.txz,.tzst) are searched, and matching pathnames of files inside archives are output in braces. When used with option--zmax=NUM, it searches the contents of compressed files and archives stored within archives up toNUMlevels. When-g,-O,-M, or-tis specified, it searches archives for files that match the specified globs, filename extensions, file signature magic bytes, or file types, respectively β and heads up, a side-effect of those options is that the compressed files and archives searched are only those with filename extensions matching known compression and archive types π. Supported compression formats: gzip (.gz), compress (.Z), zip, 7z, bzip2 (.bz,.bz2,.bzip2,.tbz,.tbz2,.tb2,.tz2), xz (.xz,.txz) and lzma (requires suffix.lzma,.tlz), zstd (.zst,.zstd,.tzst), lz4 (requires suffix.lz4), brotli (requires suffix.br), bzip3 (requires suffix.bz3) π₯.--zmax=NUMβ when used with option-zor--decompress, it searches the contents of compressed files and archives stored within archives by up toNUMexpansion stages π. The default--zmax=1only permits searching uncompressed files stored in cpio, pax, tar, zip and 7z archives; compressed files and archives get detected as binary files and are effectively ignored. Specify--zmax=2to search compressed files and archives stored in cpio, pax, tar, zip and 7z archives.NUMmay range from1to99for up to 99 decompression and de-archiving steps. And ngl, increasingNUMvalues gradually degrades performance π.
Specify ugrep --help WHAT for help on WHAT β¨.
π EXIT STATUS π
The ugrep utility exits with one of the following values, bestie:
0β one or more lines were selected π1β no lines were selected π>1β an error occurred π
And a lil exception: if -q or --quiet or --silent is used and a line is selected, the exit status is 0 even if an error occurred. Slay, we take those π«Ά.
π οΈ CONFIGURATION π οΈ
So the ug command? It's made for interactive searching, and it's literally just the ugrep --config --pretty --sort command in a trench coat π
β it loads the .ugrep config file that lives in your working directory or, if it's not there, in your home directory.
A config file is just NAME=VALUE pairs, one per line. NAME is a long option name (no -- in front, bestie), and =VALUE is the argument β which is optional and can be straight up omitted depending on the option. Empty lines? Ignored. Lines starting with #? Also ignored. Vibes only β¨
The --config=FILE option β and its abbreviated lil form ---FILE β loads the config file you point at, from the working directory or, when it's not found there, from your home directory. And if FILE isn't found or can't be read? Boom, error. No cap.
Options get parsed in this exact order: the config file loads first, then the rest of the options and arguments on the command line. That's the sequence, periodt.
Now, --save-config saves a .ugrep config file into the working directory, containing a subset of the options you specified on the command line. And "subset" is the key word here β it only saves the part of your options that won't make searches fail when combined with other options π. --save-config=FILE saves the config to FILE instead. And if FILE is -? The config gets written to standard output, iconic behavior honestly.
π GLOBBING π
Globbing is what gets used by -g (--glob and --iglob), --include, --include-dir, --include-from, --exclude, --exclude-dir, --exclude-from and --ignore-files to match pathnames or basenames in recursive searches. And heads up β quote your glob arguments for these options so your shell doesn't gobble them up first π
Globbing with --ignore-files supports gitignore syntax and rules. Same deal for every other globbing-related option, except that a glob matches filenames, not directory names. And if a glob ends in a path separator /, then it matches directory names instead of filenames β like you'd typed --include-dir or --exclude-dir. Sneaky but fair.
When a glob contains a path separator /, the full pathname is matched. Otherwise it's the basename of a file or directory that gets matched. For example, *.h matches foo.h and bar/foo.h. Meanwhile bar/*.h matches bar/foo.h but not foo.h and not bar/bar/foo.h. Want to force /*.h to match foo.h in the working directory but not bar/foo.h? Slap a leading ./ on it, or just /. πΈ
When a glob starts with a ! or a ^, like in -g^GLOB, the match is negated. Same energy: a ! (but not a ^) can be used with globs inside the files specified by --include-from, --exclude-from, and --ignore-files to negate the glob match. Empty lines or lines starting with # are ignored, as always π
β¨ Glob Syntax and Conventions β¨
* Matches anything except /.
? Matches any one character except /.
[abc-e]
Matches one character a,b,c,d,e.
[^abc-e]
Matches one character not a,b,c,d,e,/.
[!abc-e]
Matches one character not a,b,c,d,e,/.
/ When used at the start of a glob, matches the working directory.
When used at the end of a glob, matches directories only.
**/ Matches zero or more directories.
/** When used at the end of a glob, matches everything after the /.
\? Matches a ? or any other character specified after the backslash.
π Glob Matching Examples π
These are so satisfying to look at, ngl:
* Matches a, b, x/a, x/y/b
a Matches a, x/a, x/y/a, but not b, x/b, a/a/b
/* Matches a, b, but not x/a, x/b, x/y/a
/a Matches a, but not x/a, x/y/a
a?b Matches axb, ayb, but not a, b, ab, a/b
a[xy]b Matches axb, ayb but not a, b, azb
a[a-z]b
Matches aab, abb, acb, azb, but not a, b, a3b, aAb, aZb
a[^xy]b
Matches aab, abb, acb, azb, but not a, b, axb, ayb
a[^a-z]b
Matches a3b, aAb, aZb but not a, b, aab, abb, acb, azb
a/*/b Matches a/x/b, a/y/b, but not a/b, a/x/y/b
**/a Matches a, x/a, x/y/a, but not b, x/b.
a/**/b Matches a/b, a/x/b, a/x/y/b, but not x/a/b, a/b/x
a/** Matches a/x, a/y, a/x/y, but not a, b/x
a\?b Matches a?b, but not a, b, ab, axb, a/b
β οΈ Okay important one: exclude glob patterns take priority over include glob patterns when specified with options-g,--exclude,--exclude-dir,--includeandinclude-dir. Exclusion is the main character here, sorry π
Option --ignore-files specifies a file with gitignore-style globs, and the default file is .gitignore. When ignore files pop up in recursive searches, the search gets narrowed by excluding filenames and directory names matching the globs. But heads up β this gitignore glob-matching rule is different from option --exclude-from, which requires globs ending in / to match directory names. Subtle, but it matters π¦
πΏ ENVIRONMENT πΏ
GREP_PATHβ may be used to specify a file path to pattern files. Option-fuses that file path to open a pattern file when the pattern file doesn't exist. WhenGREP_PATHis undefined, it defaults to/usr/local/share/ugrep/patterns.GREP_COLORβ may be used to specify ANSI SGR parameters to highlight matches when option--coloris used. Like,1;35;40shows pattern matches in bold magenta text on a black background. It's deprecated in favor ofGREP_COLORS, but still supported (we love a comeback arc π«Ά).GREP_COLORSβ may be used to specify ANSI SGR parameters to highlight matches and other attributes when option--coloris used. Its value is a colon-separated list of ANSI SGR parameters that defaults tocx=33:mt=1;31:fn=1;35:ln=1;32:cn=1;32:bn=1;32:se=36with additional parameters for TUI colors:qp=1;32:qe=1;37;41:qm=1;32:ql=36:qb=1;35. Themt=,ms=, andmc=capabilities ofGREP_COLORStake priority overGREP_COLOR. And option--colorstakes priority overGREP_COLORS. Priority queenies, all of them π
π¨ GREP_COLORS π¨
Colors are specified as a string of colon-separated ANSI SGR parameters of the form what=substring, where substring is a semicolon-separated list of ANSI SGR codes β or one of the single-letter shortcuts: k (black), r (red), g (green), y (yellow), b (blue), m (magenta), c (cyan), w (white). Uppercase letters specify background colors, and a + qualifies a color as bright β¨. You can combine a foreground and a background color with one or more font properties: n (normal), f (faint), h (highlight), i (invert), u (underline).
Substrings may be specified for:
sl=β selected lines.cx=β context lines.rvβ swaps thesl=andcx=capabilities when-vis specified.mt=β matching text in any matching line.ms=β matching text in a selected line. The substringmt=by default.mc=β matching text in a context line. The substringmt=by default.fn=β filenames.ln=β line numbers.cn=β column numbers.bn=β byte offsets.se=β separators.rvβ a Boolean parameter, switchessl=andcx=with option-v.hlβ a Boolean parameter, enables filename hyperlinks (\33]8;;link).neβ a Boolean parameter, disables "erase in line"\33[K.qp=β TUI prompt.qe=β TUI errors.qr=β TUI regex.qm=β TUI regex meta characters.ql=β TUI regex lists and literals.qb=β TUI regex braces.
π₯ And yes, rv shows up twice in that list β once as the swap rule and once as the Boolean parameter. That's just how the page says it, bestie, I don't make the rules π
π FORMAT π
okay bestie, this is the custom-output glow-up section. Option --format=FORMAT specifies an output format for matches. Option --replace=FORMAT only replaces the matching patterns. Fields may be used in FORMAT, which expand into the following values:
%[TEXT]Fβ if option-His used: TEXT, the file pathname and separator. π%fβ the file pathname.%aβ the file basename without directory path.%pβ the directory path to the file.%zβ the file pathname in a (compressed) archive. π¦%[TEXT]Hβ if option-His used: TEXT, the quoted pathname and separator,\"and\\replace"and\.%hβ the quoted file pathname,\"and\\replace"and\.%[TEXT]Iβ if option-His used: TEXT, the pathname as XML character data and separator.%iβ the file pathname as XML character data.%[TEXT]Nβ if option-nis used: TEXT, the line number and separator.%nβ the line number of the match.%[TEXT]Kβ if option-kis used: TEXT, the column number and separator.%kβ the column number of the match.%[TEXT]Bβ if option-bis used: TEXT, the byte offset and separator.%bβ the byte offset of the match.%[TEXT]Tβ if option-Tis used: TEXT and a tab character.%tβ a tab character.%[SEP]$β set field separator to SEP for the rest of the format fields. π%[TEXT]<β if the first match: TEXT.%[TEXT]>β if not the first match: TEXT.%,β if not the first match: a comma, same as%[,]>.%:β if not the first match: a colon, same as%[:]>.%;β if not the first match: a semicolon, same as%[;]>.%|β if not the first match: a vertical bar, same as%[|]>.%[TEXT]Sβ if not the first match: TEXT and separator, see also%[SEP]$.%sβ the separator, see also%[TEXT]Sand%[SEP]$.%~β a newline character.%Mβ the number of matching lines.%mβ the number of matches.%Oβ the matching line is output as a raw string of bytes.%oβ the match is output as a raw string of bytes.%Qβ the matching line as a quoted string,\"and\\replace"and\.%qβ the match as a quoted string,\"and\\replace"and\.%Cβ the matching line formatted as a quoted C/C++ string.%cβ the match formatted as a quoted C/C++ string.%Jβ the matching line formatted as a quoted JSON string.%jβ the match formatted as a quoted JSON string.%Vβ the matching line formatted as a quoted CSV string.%vβ the match formatted as a quoted CSV string.%Xβ the matching line formatted as XML character data.%xβ the match formatted as XML character data.%wβ the width of the match, counting wide characters.%dβ the size of the match, counting bytes.%eβ the ending byte offset of the match.%Zβ the edit distance cost of an approximate match with option-Z.%uβ select unique lines only, unless option-uis used.%1β the first regex group capture of the match, and so on up to group%9, same as%[1]#; requires option-P.%[NUM]#β the regex group capture NUM; requires option-P.%[NUM]bβ the byte offset of the group capture NUM; requires option-P. Useefor the ending byte offset anddfor the byte length.%[NUM1|NUM2|...]#β the first group capture NUM that matched; requires option-P.%[NUM1|NUM2|...]bβ the byte offset of the first group capture NUM that matched; requires option-P. Useefor the ending byte offset anddfor the byte length.%[NAME]#β the group capture named NAME; requires option-Pand capturing pattern(?<NAME>PATTERN), see also%G.%[NAME]bβ the byte offset of the group capture named NAME; requires option-Pand capturing pattern(?<NAME>PATTERN). Useefor the ending byte offset anddfor the byte length.%[NAME1|NAME2|...]#β the first group capture named NAME that matched; requires option-Pand capturing pattern(?<NAME>PATTERN), see also%G.%[NAME1|NAME2|...]bβ the byte offset of the first group capture named NAME that matched; requires option-Pand capturing pattern(?<NAME>PATTERN). Useefor the ending byte offset anddfor the byte length.%Gβ list of group capture indices/names that matched; requires option-P.%[TEXT1|TEXT2|...]Gβ list of TEXT indexed by group capture indices that matched; requires option-P.%gβ the group capture index/name matched or1; requires option-P.%[TEXT1|TEXT2|...]gβ the first TEXT indexed by the first group capture index that matched; requires option-P.%%β the percentage sign.
Formatted output is written without a terminating newline, unless %~ or \n is explicitly specified in the format string. π
The [TEXT] part of a field is optional and may be omitted. When present, the argument must be placed in [] brackets, for example %[,]F to output a comma, the pathname, and a separator. β¨
%[SEP]$ and %u are switches and do not send anything to the output.
The separator used by the %F, %H, %I, %N, %K, %B, %S and %G fields may be changed by preceding the field by %[SEP]$. When [SEP] is not provided, this reverts the separator to the default separator or the separator specified with --separator. π«Ά
Formatted output is written for each matching pattern, which means that a line may be output multiple times when patterns match more than once on the same line. If field %u is specified anywhere in a format string, matching lines are output only once, unless option -u, --ungroup is specified or when more than one line of input matched the search pattern. π
Additional formatting options:
--format-begin=FORMATβ the FORMAT when beginning the search.--format-open=FORMATβ the FORMAT when opening a file and a match was found.--format-close=FORMATβ the FORMAT when closing a file and a match was found.--format-end=FORMATβ the FORMAT when ending the search.
The context options -A, -B, -C, -y, and display options --break, --heading, --color, -T, and --null have no effect on formatted output. periodt. π
β¨ EXAMPLES β¨
Okay bestie, this is the fun part β literally the whole vibe of the page is show, don't tell. Every single one of these is copy-pasteable, so go off π
Show the lines in myfile.txt that have the word patricia:
$ ugrep -w patricia myfile.txt
Same thing, but we're ignoring case now (because Patricia, PATRICIA, pAtRiCiA are all iconic and deserve equal treatment):
$ ugrep -wi patricia myfile.txt
Now here's the β¨fuzzyβ¨ one β match patricia approximately, ignoring case, and let it slide if there are up to 2 spelling errors:
$ ugrep -Z2 -wi patricia myfile.txt
Count how many lines contain patricia, case ignored:
$ ugrep -cwi patricia myfile.txt
Count how many words patricia show up, case ignored (subtle difference, but it's giving precision):
$ ugrep -cowi patricia myfile.txt
List the lines with amount plus a decimal, case ignored β and yeah, in Boolean query mode a space is an AND:
$ ugrep -i -% 'amount \d+(\.\d+)?' myfile.txt
The exact same Boolean search, but written out with -e and --and instead:
$ ugrep -wi -e amount --and '\d+(\.\d+)?' myfile.txt
List every Unicode word in a file, no cap:
$ ugrep -o '\w+' myfile.txt
List the laughing face emojis π β that's Unicode code points U+1F600 to U+1F60F:
$ ugrep -o '[\x{1F600}-\x{1F60F}]' myfile.txt
Quick vibe check: does this file contain any non-ASCII (a.k.a. Unicode) characters at all?
$ ugrep -q '[^[:ascii:]]' myfile.txt && echo "contains Unicode"
Show the line and column number of FIXME in C++ files, recursive, with one line of context before and after each matched line:
$ ugrep -C1 -R -n -k -tc++ FIXME
Same deal for long Javascript files β recursive, line and column numbers for FIXME, but only showing matches with up to 10 characters of context before and after:
$ ugrep -o -C20 -R -n -k -tjs FIXME
Find blocks of text between lines matching BEGIN and END, using a lazy quantifier *? so we only match what's necessary, plus \n to match newlines:
$ ugrep -n 'BEGIN.*\n(.*\n)*?.*END' myfile.txt
Same energy β list the C/C++ comments in a file with line numbers:
$ ugrep -n -e '//.*' -e '/\*(.*\n)*?.*\*+\/' myfile.cpp
Literally the same thing, but using the predefined pattern c++/comments:
$ ugrep -n -f c++/comments myfile.cpp
List the lines that need fixing in a C/C++ source file by hunting for FIXME while skipping any FIXME that's trapped inside quoted strings:
$ ugrep -e FIXME -N '"(\\.|\\\r?\n|[^\\\n"])*"' myfile.cpp
Same, but with the predefined pattern cpp/zap_strings:
$ ugrep -e FIXME -f cpp/zap_strings myfile.cpp
Find lines with FIXME or TODO, line numbers included:
$ ugrep -n -e FIXME -e TODO myfile.cpp
Find lines with FIXME that also contain urgent:
$ ugrep -n -e FIXME --and urgent myfile.cpp
Same result, but using a Boolean query pattern (remember: a space is AND):
$ ugrep -n -% 'FIXME urgent' myfile.cpp
Find lines with FIXME that do not also contain later:
$ ugrep -n -e FIXME --andnot later myfile.cpp
Same, but as a Boolean query pattern (space is AND, - is NOT):
$ ugrep -n -% 'FIXME -later' myfile.cpp
Output just a list of line numbers for lines with FIXME but not later:
$ ugrep -e FIXME --andnot later --format='%,%n' myfile.cpp
Recursively list all files that contain both FIXME and LICENSE anywhere in the file β not necessarily on the same line:
$ ugrep -l -%% 'FIXME LICENSE'
Find lines with FIXME in the C/C++ files stored inside a tarball:
$ ugrep -z -tc++ -n FIXME project.tgz
Recursively find lines with FIXME in C/C++ files, but skip any bak and old directories entirely:
$ ugrep -n FIXME -tc++ -g^bak/,^old/
Recursively search for the word copyright in cpio, jar, pax, tar, zip and 7z archives, in compressed and regular files, and in PDFs using a PDF filter:
$ ugrep -z -w --filter='pdf:pdftotext % -' copyright
Match the binary pattern A3hhhhA3 (hex) in a binary file without Unicode pattern matching, so -U β otherwise \xaf would be matched as the Unicode character U+00A3 with UTF-8 byte sequence C2 A3 β and show the results in hex with --hexdump, using C1 to output one hex line before and after each match:
$ ugrep -U --hexdump=C1 '\xa3[\x00-\xff]{2}\xa3' a.out
Hexdump an entire file through a pager for easy viewing:
$ ugrep -X --pager '' a.out
List every file that is not ignored by one or more .gitignore files:
$ ugrep -l '' --ignore-files
List all files containing an RPM signature, located in the rpm directory and recursively below it up to two levels deeper (3 levels total):
$ ugrep -3 -l -tRpm '' rpm/
Monitor the system log for bug reports and ungroup multiple matches within matching lines into separate lines:
$ tail -f /var/log/system.log | ugrep -u -i -w bug
Interactive fuzzy search with Boolean search queries β yes, this is as fun as it sounds:
$ ugrep -Q -l -% -Z2 --sort=best
Display all words in a MacRoman-encoded file that uses CR newlines:
$ ugrep --encoding=MACROMAN '\w+' mac.txt
Display the options related to "fuzzy" searching (a little menu of the fuzzy stuff):
$ ugrep --help fuzzy
π COPYRIGHT π
Copyright (c) 2021-2025 Robert A. van Engelen <engelen@acm.org>
ugrep is released under the BSD-3 license. Every part of the software has reasonable copyright terms that permit free redistribution β and yes, that includes the ability to reuse all or parts of the ugrep source tree. Slay, honestly π«Ά
π¦ SEE ALSO π¦
π BUGS π
Report bugs at: https://github.com/Genivia/ugrep/issues
Found something cursed? Don't suffer in silence, bestie β drop it in the issue tracker π
And that's the whole page! β¨ This gorgeous thing is ugrep version 7.8.5, dated September 15, 2026, and it's the UGREP(1) manual page β go forth and grep fearlessly, queen ππ
π¦ where this page comes from
- arch rolling: ugrep 7.8.5-1 Β· BSD-3-Clause
- nixpkgs unstable: ugrep 7.8.5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms