winget install --id=Genivia.ugrep -e
An ultra-fast, user-friendly grep replacement. Ugrep combines the best features of other grep, adds new things, and surpasses their search speeds. Includes a TUI, boolean queries (AND/OR/NOT), fuzzy search, hexdumps, searches nested archives (cpio/tar/pax/zip), compressed files (zip/gz/Z/bz2/lzma/xz/lz4/zstd), pdfs, docs, and more
ugrep: A Powerful Text Search Tool
ugrep is a high-performance, user-friendly replacement for traditional grep tools. Designed to enhance efficiency and functionality, ugrep not only surpasses conventional search speeds but also offers advanced features that make it an indispensable tool for developers and system administrators alike.
Key Features:
Audience & Benefits: Ideal for developers and system administrators requiring efficient text searching across various file types. ugrep delivers ultra-fast performance, comprehensive search capabilities across archives, compressed files, and documents, along with an intuitive interface that boosts productivity. Installation via winget ensures seamless setup on supported systems.
[ README | User Guide | Indexing | Benchmarks | Q&A ]
option -Q opens a query TUI to search files as you type!
ugrep is compatible to GNU/BSD grep, but much faster and with a ton of new features
ugrep is a drop-in replacement for BSD and GNU grep (copy or symlink ug
to grep
, and to egrep
and to fgrep
), unlike other popular grep claiming to be "grep alternatives" or "replacements" when those actually implement incompatible command-line options and use an incompatible regex matcher, i.e. Perl regex only versus POSIX BRE (grep) and ERE (egrep) when ugrep supports all regex modes
ugrep is typically faster than rg, ag, and GNU grep
full Unicode extended regex pattern syntax with multi-line pattern matching without any special command-line options
includes an interactive TUI with built-in help, Google-like search with AND/OR/NOT patterns, fuzzy search, search (nested) zip/7z/tar/pax/cpio archives, tarballs and compressed files gz/Z/bz/bz2/lzma/xz/lz4/zstd/brotli, search and hexdump binary files, search documents such as PDF, doc, docx, and output in JSON, XML, CSV or your own customized format
includes a file indexer to speed up searching slow and cold file systems
quality assurance by testing and validation to make sure ugrep is reliable
make ugrep run even faster with future updates and post reproducible performance results
consider new features requested by users when useful to support a broad use case
ug
is for interactive use, which loads an optional .ugrep configuration file with your preferences located in the working directory or home directory, ug+
also searches pdfs, documents, e-books, image metadata
ugrep
for batch use like GNU grep without a .ugrep configuration file, ugrep+
also searches pdfs, documents, e-books, image metadata
Matches Unicode patterns by default and automatically searches UTF-8, UTF-16 and UTF-32 encoded files
Matches multiple lines with \n
or \R
in regex patterns, no special options are required to do so!
Built-in help: ug --help
, where ug --help WHAT
displays options related to WHAT
you are looking for
💡 ug --help regex
, ug --help globs
, ug --help fuzzy
, ug --help format
.
User-friendly with customizable configuration files used by the ug
command intended for interactive use that loads a .ugrep configuration file with your preferences
ug PATTERN ... ugrep --config PATTERN ...
💡 ug --save-config ...options-you-want-to-save...
saves a .ugrep config file in the working directory so that the next time you run ug
there it uses these options. Do this in your home directory to save a .ugrep config file with options you generally want to use.
Interactive query TUI, press F1 or CTRL-Z for help and TAB/SHIFT-TAB to navigate to dirs and files
ug -Q ug -Q -e PATTERN
💡 -Q
replaces PATTERN
on the command line to let you enter patterns interactively in the TUI. In the TUI use ALT+letter keys to toggle short "letter options" on/off, for example ALT-n (option -n
) to show/hide line numbers.
Search the contents of archives (zip, tar, pax, jar, cpio, 7z) and compressed files (gz, Z, bz, bz2, lzma, xz, lz4, zstd, brotli)
ug -z PATTERN ... ug -z --zmax=2 PATTERN ...
💡 specify -z --zmax=2
to search compressed files and archives nested within archives. The --zmax
argument may range from 1 (default) to 99 for up to 99 decompression and de-archiving steps to search nested archives
Search with Google-like Boolean query patterns using -%
patterns with AND
(or just space), OR
(or a bar |
), NOT
(or a dash -
), using quotes to match exactly, and grouping with ( )
(shown on the left side below); or with options -e
(as an "or"), --and
, --andnot
, and --not
regex patterns (shown on the right side below):
ug -% 'A B C' ... ug -e 'A' --and 'B' --and 'C' ...
ug -% 'A|B C' ... ug -e 'A' -e 'B' --and 'C' ...
ug -% 'A -B -C' ... ug -e 'A' --andnot 'B' --andnot 'C' ...
ug -% 'A -(B|C)'... ug -e 'A' --andnot 'B' --andnot 'C' ...
ug -% '"abc" "def"' ... ug -e '\Qabc\E' --and '\Qdef\E' ...
where A
, B
and C
are arbitrary regex patterns (use option -F
to search strings)
💡 specify option -%%
(--bool --files
) to apply the Boolean query to files as a whole: a file matches if all Boolean conditions are satisfied by matching patterns file-wide. Otherwise, Boolean conditions apply to single lines by default, since grep utilities are generally line-based pattern matchers. Option --stats
displays the query in human-readable form after the search completes.
Search pdf, doc, docx, e-book, and more with ug+
using filters associated with filename extensions:
ug+ PATTERN ...
or specify --filter
with a file type to use a filter utility:
ug --filter='pdf:pdftotext % -' PATTERN ...
ug --filter='doc:antiword %' PATTERN ...
ug --filter='odt,docx,epub,rtf:pandoc --wrap=preserve -t plain % -o -' PATTERN ...
ug --filter='odt,doc,docx,rtf,xls,xlsx,ppt,pptx:soffice --headless --cat %' PATTERN ...
ug --filter='pem:openssl x509 -text,cer,crt,der:openssl x509 -text -inform der' PATTERN ...
ug --filter='latin1:iconv -f LATIN1 -t UTF-8' PATTERN ...
💡 the ug+
command is the same as the ug
command, but also uses filters to search PDFs, documents, and image metadata
Display horizontal context with option -o
(--only-matching
) and context options -ABC
, e.g. to find matches in very long lines, such as Javascript and JSON sources:
ug -o -C20 -nk PATTERN longlines.js
💡 -o -C20
fits all matches with context in 20 characters before and 20 charactess after a match (i.e. 40 Unicode characters total), -nk
outputs line and column numbers.
Find approximate pattern matches with fuzzy search, within the specified Levenshtein distance
ug -Z PATTERN ... ug -Z3 PATTTERN ...
💡 -Zn
matches up to n
extra, missing or replaced characters, -Z+n
matches up to n
extra characters, -Z-n
matches with up to n
missing characters and -Z~n
matches up to n
replaced characters. -Z
defaults to -Z1
.
Fzf-like search with regex (or fixed strings with -F
), fuzzy matching with up to 4 extra characters with -Z+4
and words only with -w
, using -%%
for file-wide Boolean searches
ug -Q -%% -l -w -Z+4 --sort=best
💡 -l
lists the matching files in the TUI, press TAB
then ALT-y
to view a file, SHIFT-TAB
and Alt-l
to go back to view the list of matching files ordered by best match
Search binary files and display hexdumps with binary pattern matches (Unicode text or -U
for byte patterns)
ug --hexdump -U BYTEPATTERN ... ug --hexdump TEXTPATTERN ...
ug -X -U BYTEPATTERN ... ug -X TEXTPATTERN ...
ug -W -U BYTEPATTERN ... ug -W TEXTPATTERN ...
💡 --hexdump=4chC1
displays 4
columns of hex without a character column c
, no hex spacing h
, and with one extra hex line C1
before and after a match.
Include files to search by file types or file "magic bytes" or exclude them with ^
ug -t TYPE PATTERN ... ug -t ^TYPE PATTERN ...
ug -M 'MAGIC' PATTERN ... ug -M '^MAGIC' PATTERN ...
Include files and directories to search that match gitignore-style globs or exclude them with ^
ug -g 'FILEGLOB' PATTERN ... ug -g '^FILEGLOB' PATTERN ...
ug -g 'DIRGLOB/' PATTERN ... ug -g '^DIRGLOB/' PATTERN ...
ug -g 'PATH/FILEGLOB' PATTERN ... ug -g '^PATH/FILEGLOB' PATTERN ...
ug -g 'PATH/DIRGLOB/' PATTERN ... ug -g '^PATH/DIRGLOB/' PATTERN ...
Include files to search by filename extensions (suffix) or exclude them with ^
, a shorthand for -g"*.EXT"
ug -O EXT PATTERN ... ug -O ^EXT PATTERN ...
Include hidden files (dotfiles) and directories to search (omitted by default)
ug -. PATTERN ... ug -g'.*,.*/' PATTERN ...
💡 specify hidden
in your .ugrep to always search hidden files with ug
.
Exclude files specified by .gitignore etc.
ug --ignore-files PATTERN ... ug --ignore-files=.ignore PATTERN ...
💡 specify ignore-files
in your .ugrep to always ignore them with ug
. Add additional ignore-files=...
as desired.
Search patterns excluding negative patterns ("match this but not that")
ug -e PATTERN -N NOTPATTERN ... ug -e '[0-9]+' -N 123 ...
Use predefined regex patterns to search source code, javascript, XML, JSON, HTML, PHP, markdown, etc.
ug PATTERN -f c++/zap_comments -f c++/zap_strings ...
ug PATTERN -f php/zap_html ...
ug -f js/functions ... | ug PATTERN ...
Sort matching files by name, best match, size, and time
ug --sort PATTERN ... ug --sort=size PATTERN ...
ug --sort=changed PATTERN ... ug --sort=created PATTERN ...
ug -Z --sort=best PATTERN ... ug --no-sort PATTERN ...
Output results in CSV, JSON, XML, and user-specified formats
ug --csv PATTERN ... ug --json PATTERN ...
ug --xml PATTERN ... ug --format='file=%f line=%n match=%O%~' PATTERN ...
💡 ug --help format
displays help on format %
fields for customized output.
Search with PCRE's Perl-compatible regex patterns and display or replace subpattern matches
ug -P PATTERN ... ug -P --format='%1 and %2%~' 'PATTERN(SUB1)(SUB2)' ...
Replace patterns in the output with -P and --replace replacement text, optionally containing %
formatting fields, using -y
to pass the rest of the file through:
ug --replace='TEXT' PATTERN ... ug -y --replace='TEXT' PATTERN ...
ug --replace='(%m:%o)' PATTERN ... ug -y --replace='(%m:%o)' PATTERN ...
ug -P --replace='%1' PATTERN ... ug -y -P --replace='%1' PATTERN ...
💡 ug --help format
displays help on format %
fields to optionally use with --replace
.
Search files with a specific encoding format such as ISO-8859-1 thru 16, CP 437, CP 850, MACROMAN, KOI8, etc.
ug --encoding=LATIN1 PATTERN ...
$ brew install ugrep
or install with MacPorts:
$ sudo port install ugrep
This installs the ugrep
and ug
commands, where ug
is the same as ugrep
but also loads the configuration file .ugrep when present in the working
directory or home directory.
Install with Winget
winget install Genivia.ugrep
Or install with Chocolatey
choco install ugrep
Or install with Scoop scoop install ugrep
Or download the full-featured ugrep.exe
executable as release artifact from
. The zipped release contains the
main ugrep.exe
binary as well as ug.exe
. The ug
command, intended for
interactive use, loads and reads in settings from the .ugrep
configuration
file (when present in the working directory or home directory).
Add ugrep.exe
and ug.exe
to your execution path: go to Settings and
search for "Path" in Find a Setting. Select environment variables ->
Path -> New and add the directory where you placed the ugrep.exe
and
ug.exe
executables.
>[!TIP]
> Practical hints on using ugrep.exe
and ug.exe
on the Windows command line:
>
>- when quoting patterns and arguments on the command line, do not use single
>'
quotes but use "
instead; most Windows command utilities consider
>the single '
quotes part of the command-line argument!
>- file and directory globs are best specified with option -g/GLOB
instead of
>the usual GLOB
command line arguments to select files and directories to
>search, especially for recursive searches;
>- when specifying an empty pattern ""
to match all input, this may be ignored
>by some Windows command interpreters such as Powershell, in that case you
>must specify option --match
instead;
>- to match newlines in patterns, you may want to use \R
instead of \n
to
>match any Unicode newlines, such as \r\n
pairs and single \r
and \n
.
$ apk add ugrep ugrep-doc
Check for version info.
$ pacman -S ugrep
Check for version info.
First enable the EPEL repository, then you can install ugrep.
$ dnf install ugrep
Check for version info.
$ apt-get install ugrep
Check for version info. To build and try
ugrep
locally, see "All platforms" build steps further below.
$ dnf install ugrep
Check for version info.
$ pkg install ugrep
Check for version info.
$ pkgman install cmd:ugrep
Check for
version info. To build and try ugrep
locally, see "All platforms" build
steps further below.
You can use the standard NetBSD package installer (pkgsrc):
$ pkg_add ugrep
Check for version info.
$ zypper install ugrep
Check for version info.
First enable the EPEL repository, then you can install ugrep.
$ dnf install ugrep
Check for version info.
Clone ugrep
with
$ git clone https://github.com/Genivia/ugrep
Or visit to download a specific release.
You can always add these later, when you need these features:
Option -P
(Perl regular expressions) requires either the PCRE2 library
(recommended) or the Boost.Regex library (optional fallback). If PCRE2 is
not installed, install PCRE2 with e.g. sudo apt-get install -y libpcre2-dev
or download PCRE2 and follow the installation
instructions. Alternatively,
download Boost.Regex and run
./bootstrap.sh
and sudo ./b2 --with-regex install
. See
Boost: getting started.
Option -z
(compressed files and archives search) requires the
zlib library installed. It is installed on most
systems. If not, install it, e.g. with sudo apt-get install -y libz-dev
.
To search .bz
and .bz2
files, install the
bzip2 library (recommended), e.g. with
sudo apt-get install -y libbz2-dev
. To search .lzma
and .xz
files,
install the lzma library (recommended), e.g. with
sudo apt-get install -y liblzma-dev
. To search .lz4
files, install the
lz4 library (optional, not required), e.g.
with sudo apt-get install -y liblz4-dev
. To search .zst
files, install
the zstd library (optional, not required),
e.g. with sudo apt-get install -y libzstd-dev
. To search .br
files,
install the brotli library (optional, not
required), e.g. with sudo apt-get install -y libbrotli-dev
. To search
.bz3
files, install the bzip3
library (optional, not required), e.g. with sudo apt-get install -y bzip3
.
>[!TIP]
>Even if your system has command line utilities, such as bzip2
, that
>does not necessarily mean that the development libraries such as libbz2
are
>installed. The development libraries should be installed.
>
>Some Linux systems may not be configured to load dynamic libraries from
>/usr/local/lib
, causing a library load error when running ugrep
. To
>correct this, add export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
>to your ~/.bashrc
file. Or run sudo ldconfig /usr/local/lib
.
Execute the ./build.sh
script to build ugrep
:
$ cd ugrep
$ ./build.sh
This builds the ugrep
executable in the ugrep/src
directory with
./configure
and make -j
, verified with make test
. When all tests pass,
the ugrep
executable is copied to ugrep/bin/ugrep
and the symlink
ugrep/bin/ug -> ugrep/bin/ugrep
is added for the ug
command.
Note that ug
is the same as ugrep
but also loads the configuration file
.ugrep when present in the working directory or home directory. This means
that you can define your default options for ug
in .ugrep.
Alternative paths to installed or local libraries may be specified with
./build.sh
. To get help on the available build options:
$ ./build.sh --help
You can build static executables by specifying:
$ ./build.sh --enable-static
This may fail if libraries don't link statically, such as brotli. In that case
try ./build.sh --enable-static --without-brotli
.
You can build ugrep
with customized defaults enabled, such as a pager:
$ ./build.sh --enable-pager
Options to select defaults for builds include:
--help
display build options--enable-static
build static executables, if possible--enable-hidden
always search hidden files and directories--enable-pager
always use a pager to display output on terminals--enable-pretty
colorize output to terminals and add filename headings--disable-auto-color
disable automatic colors, requires ugrep option --color=auto
to show colors--disable-mmap
disable memory mapped files--disable-sse2
disable SSE2 and AVX optimizations--disable-avx2
disable AVX2 and AVX512BW optimizations, but compile with SSE2 when supported--disable-neon
disable ARM NEON/AArch64 optimizations--with-grep-path
the default -f
path if GREP_PATH
is not defined--with-grep-colors
the default colors if GREP_COLORS
is not definedAfter the build completes, copy ugrep/bin/ugrep
and ugrep/bin/ug
to a
convenient location, for example in your ~/bin
directory. Or, if you may want
to install the ugrep
and ug
commands and man pages:
$ sudo make install
This also installs the pattern files with predefined patterns for option -f
at /usr/local/share/ugrep/patterns/
. Option -f
first checks the working
directory for the presence of pattern files, if not found checks environment
variable GREP_PATH
to load the pattern files, and if not found reads the
installed predefined pattern files.
Unfortunately, git clones do not preserve timestamps which means that you may
run into "WARNING: 'aclocal-1.15' is missing on your system." or that
autoheader was not found when running make
.
To work around this problem, run:
$ autoreconf -fi
$ ./build.sh
GCC 8 and greater may produce warnings of the sort "note: parameter passing for argument ... changed in GCC 7.1". These warnings should be ignored.
A Dockerfile is included to build ugrep
in a Ubuntu container.
Developers may want to use sanitizers to verify the ugrep code when making significant changes, for example to detect data races with the ThreadSanitizer:
$ ./build.sh CXXFLAGS='-fsanitize=thread -O1 -g'
We checked ugrep
with the clang AddressSanitizer, MemorySanitizer,
ThreadSanitizer, and UndefinedBehaviorSanitizer. These options incur
significant runtime overhead and should not be used for the final build.
For an up-to-date performance comparison of the latest ugrep, please see the ugrep performance benchmarks. Ugrep is faster than GNU grep, Silver Searcher, ack, sift. Ugrep's speed beats ripgrep in most benchmarks.
This specifies -j
case insensitive searches with the Vim :grep
command. For case sensitive searches, remove \ -j
from grepprg
. Multiple
matches on the same line are listed in the quickfix window separately. If this
is not desired, remove \ -u
from grepprg
. With this change, only the first
match on a line is shown. Option --ignore-files
skips files specified in
.gitignore
files, when present. To limit the depth of recursive searches to
the current directory only, append \ -1
to grepprg
.
You can now invoke the Vim :grep
command in Vim to search files on a
specified PATH
for PATTERN
matches:
:grep PATTERN [PATH]
If you omit PATH
, then the working directory is searched. Use %
as PATH
to search only the currently opened file in Vim:
:grep PATTERN %
The :grep
command shows the results in a
quickfix window
that allows you to quickly jump to the matches found.
To open a quickfix window with the latest list of matches:
:copen
Double-click on a line in this window (or select a line and press ENTER) to
jump to the file and location in the file of the match. Enter commands :cn
and :cp
to jump to the next or previous match, respectively. To update the
search results in the quickfix window, just grep them. For example, to
recursively search C++ source code marked FIXME
in the working directory:
:grep -tc++ FIXME
To close the quickfix window:
:cclose
You can use ugrep options with the :grep
command, for example to
select single- and multi-line comments in the current file:
:grep -f c++/comments %
Only the first line of a multi-line comment is shown in quickfix, to save
space. To show all lines of a multi-line match, remove %-G
from
grepformat
.
A popular Vim tool is ctrlp.vim, which is installed with:
$ cd ~/.vim
$ git clone https://github.com/kien/ctrlp.vim.git bundle/ctrlp.vim
CtrlP uses ugrep by adding the following lines to your .vimrc
:
if executable('ugrep')
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_match_window='bottom,order:ttb'
let g:ctrlp_user_command='ugrep "" %s -Rl -I --ignore-files -3'
endif
where -I
skips binary files, option --ignore-files
skips files specified in
.gitignore
files, when present, and option -3
restricts searching
directories to three levels (the working directory and up to two levels below).
Start Vim then enter the command:
:helptags ~/.vim/bundle/ctrlp.vim/doc
To view the CtrlP documentation in Vim, enter the command:
:help ctrlp.txt
Thanks to Manuel Uberti,
you can now use ugrep in Emacs. To use ugrep instead of GNU grep
within Emacs, add the following line to your .emacs.d/init.el
file:
(setq-default xref-search-program ‘ugrep)
This means that Emacs commands such as project-find-regexp
that rely on
Xref can
now leverage the power of ugrep.
Furthermore, it is possible to use grep
in the Emacs grep
commands.
For instance, you can run lgrep
with ugrep
by customizing grep-template
to something like the following:
(setq-default grep-template "ugrep --color=always -0Iinr -e ")
If you do not have Emacs version 29 (or greater) you can download and build Emacs from the Emacs master branch, or enable Xref integration with ugrep manually:
(with-eval-after-load 'xref
(push '(ugrep . "xargs -0 ugrep --null -ns -e ")
xref-search-program-alist)
(setq-default xref-search-program 'ugrep))
ugrep supports all standard GNU/BSD grep command-line options and improves many of them too. See notable improvements over grep.
In fact, executing ugrep
with options -U
, -Y
, -.
and --sort
makes it
behave like egrep
, permitting empty patterns to match and search hidden files
instead of ignoring them. See grep equivalence.
You can create convenient grep aliases with or without options
-Y
, -.
and --sort
or include other options as desired. If you really
must stick exactly to GNU/BSD grep ASCII/LATIN1 patterns, use options -U
and --grep
to disable Unicode pattern matching and to reassign options -z
and -Z
to --null-data
and --null
, respectively.
You can also create grep
, egrep
and fgrep
executables by symlinking or
copying ugrep
to those names. When the ugrep
(or ugrep.exe
) executable
is copied as grep
(grep.exe
), egrep
(egrep.exe
), fgrep
(fgrep.exe
), then options -Y
and -.
are automatically enabled together
with either -G
for grep
, -E
for egrep
and -F
for fgrep
. In
addition, when copied as zgrep
, zegrep
and zfgrep
, option
--decompress
is enabled. For example, when ugrep
is copied as zegrep
,
options --decompress
, -E
, -Y
, -.
and --sort
are enabled.
Likewise, symlinks and hard links can be used to create grep
, egrep
and
fgrep
replacements in the usual installation directories. For example:
sudo ln -s `which ugrep` /opt/local/bin/grep
sudo ln -s `which ugrep` /opt/local/bin/egrep
sudo ln -s `which ugrep` /opt/local/bin/fgrep
sudo ln -s `which ugrep` /opt/local/bin/zgrep
sudo ln -s `which ugrep` /opt/local/bin/zegrep
sudo ln -s `which ugrep` /opt/local/bin/zfgrep
The /opt/local/bin
here is an example and may or may not be in your $path
and may or may not be found, so please adjust as necessary. Caution:
bash does not obey the linked name when executing the program, reverting to
the name ugrep
instead, which negates all internal compatibility settings.
To avoid this, copy the executables instead of linking!
When linking or copying ugrep
to grep
, egrep
, fgrep
, zgrep
, zegrep
,
zfgrep
, options -z
and -Z
are reassigned for compatibility to GNU/BSD
grep options --null-data
and --null
, respectively.
-Y
enables empty matches, so for example the pattern a*
matches every
line instead of a sequence of a
's. By default in ugrep, the pattern a*
matches a sequence of a
's. Moreover, in ugrep the pattern a*b*c*
matches
what it is supposed to match by default. See improvements.-.
searches hidden files (dotfiles). By default, hidden files are ignored,
like most Unix utilities.--sort
specifies output sorted by pathname, showing sorted matching files
first followed by sorted recursive matches in subdirectories. Otherwise,
matching files are reported in no particular order to improve performance;-z
and -Z
are reassigned to --null-data
and --null
and no
longer enable --decompress
and --fuzzy
searching modes.There is one minor difference with GNU/BSD grep:
-Dread
and -dread
which are not recommended, see
improvements for an explanation.-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
-Q and 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.
The command can be specified with option --view, or defaults to
environment variable PAGER when defined, or EDITOR. Press Tab and
Shift-Tab to navigate directories and to select a file to search.
Press Enter to select lines to output. Press ALT-l for option -l
to list files, ALT-n for -n, etc. Non-option commands include
ALT-] to increase context. See also options --no-confirm, --delay,
--split and --view.
--no-confirm
Do not confirm actions in -Q query TUI. The default is confirm.
--delay=DELAY
Set the default -Q key response delay. Default is 3 for 300ms.
--split
Split the -Q query TUI screen on startup.
--view[=COMMAND]
Use COMMAND to view/edit a file in -Q query TUI by pressing CTRL-Y.
This option starts a user interface to enter search patterns interactively:
-c
to count matches. Pressing Alt-c again disables -c
. Options
can be toggled with the Alt key while searching or when viewing the help
screen. If Alt/Meta keys are not working (e.g. X11 xterm), then press
CTRL-O followed by the key corresponding to the option. Alt keys may work
in xterm by adding xterm*metaSendsEscape: true
to ~/.Xdefaults`.-g
file and directory matching globs, a
comma-separated list of gitignore-style glob patterns. Presssing ESC returns
control to the query pattern prompt (the globs are saved). When a glob is
preceded by a !
or a ^
, skips files whose name matches the glob When a
glob contains a /
, full pathnames are matched. Otherwise basenames are
matched. When a glob ends with a /
, directories are matched.Q>
(normal), F>
(fixed strings),
G>
(basic regex), P>
(Perl matching), and Z>
(fuzzy matching).
When the --glob=
prompt is shown, a comma-separated list of gitignore-style
glob patterns may be entered. Presssing ESC returns control to the pattern
prompt.--view
.--view=COMMAND
. Otherwise, the PAGER
or EDITOR
environment variables are used to invoke the command with CTRL-Y. Filenames
must be enabled and visible in the output to use this feature.--color
option.DELAY
value such as 1. However,
lower values may increase system load as a result of repeatedly initiating
and cancelling searches by each key pressed.--heading
is enabled by
default. Press Alt-+ to switch headings off.Query TUI key mapping:
key(s) | function |
---|---|
Alt-key | toggle ugrep command-line option corresponding to key |
Alt-/ xxxx/ | insert Unicode hex code point U+xxxx |
Esc Ctrl-C | go back or exit |
Ctrl-Q | quick exit and output the results selected in selection mode |
Tab | chdir to the directory of the file shown at the top of the screen or select file |
Shift-Tab | chdir one level up or deselect file |
Enter | enter selection mode and toggle selected lines to output on exit |
Up Ctrl-P | move up |
Down Ctrl-N | move down |
Left Ctrl-B | move left |
Right Ctrl-F | move right |
PgUp Ctrl-G | move display up by a page |
PgDn Ctrl-D | move display down by a page |
Alt-Up | move display up by 1/2 page (MacOS Shift-Up ) |
Alt-Down | move display down by 1/2 page (MacOS Shift-Down ) |
Alt-Left | move display left by 1/2 page (MacOS Shift-Left ) |
Alt-Right | move display right by 1/2 page (MacOS Shift-Right ) |
Home Ctrl-A | move cursor to the beginning of the line |
End Ctrl-E | move cursor to the end of the line |
Ctrl-K | delete after cursor |
Ctrl-L | refresh screen |
Ctrl-O +key |
To interactively search the files in the working directory and below:
ug -Q
Same, but restricted to C++ files only and ignoring .gitignore
files:
ug -Q -tc++ --ignore-files
To interactively search all makefiles in the working directory and below:
ug -Q -g 'Makefile*' -g 'makefile*'
Same, but for up to 2 directory levels (working and one subdirectory level):
ug -Q -2 -g 'Makefile*' -g 'makefile*'
To interactively view the contents of main.cpp
and search it, where -y
shows any nonmatching lines as context:
ug -Q -y main.cpp
To interactively search main.cpp
, starting with the search pattern TODO
and
a match context of 5 lines (context can be interactively enabled and disabled,
this also overrides the default context size of 2 lines):
ug -Q -C5 -e TODO main.cpp
To view and search the contents of an archive (e.g. zip, tarball):
ug -Q -z archive.tar.gz
To interactively select files from project.zip
to decompress with unzip
,
using ugrep query selection mode (press Enter to select lines):
unzip project.zip `zipinfo -1 project.zip | ugrep -Q`
--bool, -%, -%%
Specifies Boolean query patterns. A Boolean query pattern is
composed of `AND', `OR', `NOT' operators and grouping with `(' `)'.
Spacing between subpatterns is the same as `AND', `|' is the same
as `OR' and a `-' is the same as `NOT'. The `OR' operator binds
more tightly than `AND'. For example, --bool 'A|B C|D' matches
lines with (`A' or `B') and (`C' or `D'), --bool 'A -B' matches
lines with `A' and not `B'. Operators `AND', `OR', `NOT' require
proper spacing. For example, --bool 'A OR B AND C OR D' matches
lines with (`A' or `B') and (`C' or `D'), --bool 'A AND NOT B'
matches lines with `A' without `B'. Quoted subpatterns are matched
literally as strings. For example, --bool 'A "AND"|"OR"' matches
lines with `A' and also either `AND' or `OR'. Parentheses are used
for grouping. For example, --bool '(A B)|C' matches lines with `A'
and `B', or lines with `C'. Note that all subpatterns in a Boolean
query pattern are regular expressions, unless -F is specified.
Options -E, -F, -G, -P and -Z can be combined with --bool to match
subpatterns as strings or regular expressions (-E is the default.)
This option does not apply to -f FILE patterns. The double short
option -%% enables options --bool --files. Option --stats displays
the Boolean search patterns applied. See also options --and,
--andnot, --not, --files and --lines.
--files
Boolean file matching mode, the opposite of --lines. When combined
with option --bool, matches a file if all Boolean conditions are
satisfied. For example, --bool --files 'A B|C -D' matches a file
if some lines match `A', and some lines match either `B' or `C',
and no line matches `D'. See also options --and, --andnot, --not,
--bool and --lines. The double short option -%% enables options
--bool --files.
--lines
Boolean line matching mode for option --bool, the default mode.
--and [[-e] PATTERN] ... -e PATTERN
Specify additional patterns to match. Patterns must be specified
with -e. Each -e PATTERN following this option is considered an
alternative pattern to match, i.e. each -e is interpreted as an OR
pattern. For example, -e A -e B --and -e C -e D matches lines with
(`A' or `B') and (`C' or `D'). Note that multiple -e PATTERN are
alternations that bind more tightly together than --and. Option
--stats displays the search patterns applied. See also options
--not, --andnot, and --bool.
--andnot [[-e] PATTERN] ...
Combines --and --not. See also options --and, --not, and --bool.
--not [-e] PATTERN
Specifies that PATTERN should not match. Note that -e A --not -e B
matches lines with `A' or lines without a `B'. To match lines with
`A' that have no `B', specify -e A --andnot -e B. Option --stats
displays the search patterns applied. See also options --and,
--andnot, and --bool.
--stats
Output statistics on the number of files and directories searched,
and the inclusion and exclusion constraints applied.
Note that the --and
, --not
, and --andnot
options require -e PATTERN
.
The -%
option makes all patterns Boolean-based, supporting the following
logical operations listed from the highest level of precedence to the lowest:
operator | alternative | result |
---|---|---|
"x" | match x literally and exactly as specified (using the standard regex escapes \Q and \E ) | |
( ) | Boolean expression grouping | |
-x | NOT x | inverted match, i.e. matches if x does not match |
x|y | x OR y | matches lines with x or y |
x y | x AND y | matches lines with both x and y |
x
and y
are subpatterns that do not start with the special symbols |
,
-
, and (
(use quotes or a \
escape to match these);
-
and NOT
are the same and take precedence over OR
, which means that
-x|y
== (-x)|y
for example.
|
and OR
are the same and take precedence over AND
, which means that
x y|z
== x (y|z)
for example;
The --stats
option displays the Boolean queries in human-readable form
converted to CNF (Conjunctive Normal Form), after the search is completed.
To show the CNF without a search, read from standard input terminated by an
EOF, like echo | ugrep -% '...' --stats
.
Subpatterns are color-highlighted in the output, except those negated with
NOT
(a NOT
subpattern may still show up in a matching line when using an
OR-NOT pattern like x|-y
). Note that subpatterns may overlap. In that
case only the first matching subpattern is color-highlighted.
Multiple lines may be matched when subpatterns match newlines. There is one
exception however: subpatterns ending with (?=X)
lookaheads may not match
when X
spans multiple lines.
Empty patterns match any line (grep standard). Therefore, -% 'x|""|y'
matches everything and x
and y
are not color-highlighted. Option -y
should be used to show every line as context, for example -y 'x|y'
.
Fzf-like interactive querying (Boolean search with fixed strings with fuzzy
matching to allow e.g. up to 4 extra characters matched with -Z+4
in words
with -w
), press TAB and ALT-y to view a file with matches. Press SHIFT-TAB
and ALT-l to go back to the list of matching files:
ug -Q -%% -l -w -F -Z+4 --sort=best
To recursively find all files containing both hot
and dog
anywhere in the
file with option --files
:
ug -%% 'hot dog'
ug --files -e hot --and dog
To find lines containing both hot
and dog
in myfile.txt
:
ug -% 'hot dog' myfile.txt
ug -e hot --and dog myfile.txt
To find lines containing place
and then also hotdog
or taco
(or both) in
myfile.txt
:
ug -% 'hotdog|taco place' myfile.txt
ug -e hotdog -e taco --and place myfile.txt
Same, but exclude lines matching diner
:
ug -% 'hotdog|taco place -diner' myfile.txt
ug -e hotdog -e taco --and place --andnot diner myfile.txt
To find lines with diner
or lines that match both fast
and food
but not bad
in myfile.txt
:
ug -% 'diner|(fast food -bad)' myfile.txt
To find lines with fast food
(exactly) or lines with diner
but not bad
or old
in myfile.txt
:
ug -% '"fast food"|diner -bad -old' myfile.txt
Same, but using a different Boolean expression that has the same meaning:
ug -% '"fast food"|diner -(bad|old)' myfile.txt
To find lines with diner
implying good
in myfile.txt
(that is, show lines
with good
without diner
and show lines with diner
but only those with
good
, which is logically implied!):
ug -% 'good|-diner' myfile.txt
ug -e good --not diner myfile.txt
To find lines with foo
and -bar
and "baz"
in myfile.txt
(not that -
and "
should be matched using \
escapes and with --and -e -bar
):
ug -% 'foo \-bar \"baz\"' myfile.txt
ug -e foo --and -e -bar --and '"baz"' myfile.txt
To search myfile.cpp
for lines with TODO
or FIXME
but not both on the
same line, like XOR:
ug -% 'TODO|FIXME -(TODO FIXME)' myfile.cpp
ug -e TODO -e FIXME --and --not TODO --not FIXME myfile.cpp
See also Boolean query patterns with -%, -%%, --and, --not for more powerful Boolean query options than the traditional GNU/BSD grep options.
To display lines in file myfile.sh
but not lines matching ^[ \t]*#
:
ug -v '^[ \t]*#' myfile.sh
To search myfile.cpp
for lines with FIXME
and urgent
, but not Scotty
:
ugrep FIXME myfile.cpp | ugrep urgent | ugrep -v Scotty
Same, but using -%
for Boolean queries:
ug -% 'FIXME urgent -Scotty' myfile.cpp
To search for decimals using pattern \d+
that do not start with 0
using
negative pattern 0\d+
and excluding 555
:
ug -e '\d+' -N '0\d+' -N 555 myfile.cpp
To search for words starting with disp
without matching display
in file
myfile.py
by using a "negative pattern" -N '/'
where -N
specifies an additional negative pattern to skip matches:
ug -e '\' myfile.py
To search for lines with the word display
in file myfile.py
skipping this
word in strings and comments, where -f
specifies patterns in files which are
predefined patterns in this case:
ug -n -w 'display' -f python/zap_strings -f python/zap_comments myfile.py
To display lines that are not blank lines:
ug -x -e '.*' -N '\h*' myfile.py
Same, but using -v
and -x
with \h*
, i.e. pattern ^\h*$
:
ug -v -x '\h*' myfile.py
To recursively list all Python files that do not contain the word display
,
allowing the word to occur in strings and comments:
ug -RL -tPython -w 'display' -f python/zap_strings -f python/zap_comments
Binary, ASCII and UTF-8 files do not require this option to search them. Also
UTF-16 and UTF-32 files do not require this option to search them, assuming
that UTF-16 and UTF-32 files start with a UTF BOM
(byte order mark) as usual.
Other file encodings require option --encoding=ENCODING
:
encoding | parameter |
---|---|
ASCII | n/a |
UTF-8 | n/a |
UTF-16 with BOM | n/a |
UTF-32 with BOM | n/a |
UTF-16 BE w/o BOM | UTF-16 or UTF-16BE |
UTF-16 LE w/o BOM | UTF-16LE |
UTF-32 w/o BOM | UTF-32 or UTF-32BE |
UTF-32 w/o BOM | UTF-32LE |
Latin-1 | LATIN1 or ISO-8859-1 |
ISO-8859-1 | ISO-8859-1 |
ISO-8859-2 | ISO-8859-2 |
ISO-8859-3 | ISO-8859-3 |
ISO-8859-4 | ISO-8859-4 |
ISO-8859-5 | ISO-8859-5 |
ISO-8859-6 | ISO-8859-6 |
ISO-8859-7 | ISO-8859-7 |
ISO-8859-8 | ISO-8859-8 |
ISO-8859-9 | ISO-8859-9 |
ISO-8859-10 | ISO-8859-10 |
ISO-8859-11 | ISO-8859-11 |
ISO-8859-13 | ISO-8859-13 |
ISO-8859-14 | ISO-8859-14 |
ISO-8859-15 | ISO-8859-15 |
ISO-8859-16 | ISO-8859-16 |
MAC (CR=newline) | MAC |
MacRoman (CR=newline) | MACROMAN |
EBCDIC | EBCDIC |
DOS code page 437 | CP437 |
DOS code page 850 | CP850 |
DOS code page 858 | CP858 |
Windows code page 1250 | CP1250 |
Windows code page 1251 | CP1251 |
Windows code page 1252 | CP1252 |
Windows code page 1253 | CP1253 |
Windows code page 1254 | CP1254 |
Windows code page 1255 | CP1255 |
Windows code page 1256 | CP1256 |
Windows code page 1257 | CP1257 |
Windows code page 1258 | CP1258 |
KOI8-R | KOI8-R |
KOI8-U | KOI8-U |
KOI8-RU | KOI8-RU |
Note that regex patterns are always specified in UTF-8 (includes ASCII). To search binary files with binary patterns, see searching and displaying binary files with -U, -W, and -X.
To recursively list all files that are ASCII (i.e. 7-bit):
ug -L '[^[:ascii:]]'
To recursively list all files that are non-ASCII, i.e. UTF-8, UTF-16, and UTF-32 files with non-ASCII Unicode characters (U+0080 and up):
ug -l '[^[:ascii:]]'
To check if a file contains non-ASCII Unicode (U+0080 and up):
ug -q '[^[:ascii:]]' myfile && echo "contains Unicode"
To remove invalid Unicode characters from a file (note that -o
may not work
because binary data is detected and rejected and newlines are added, but
--format="%o%
does not check for binary and copies the match "as is"):
ug "[\p{Unicode}\n]" --format="%o" badfile.txt
To recursively list files with invalid UTF content (i.e. invalid UTF-8 byte
sequences or files that contain any UTF-8/16/32 code points that are outside
the valid Unicode range) by matching any code point with .
and by using a
negative pattern -N '\p{Unicode}'
to ignore each valid Unicode character:
ug -l -e '.' -N '\p{Unicode}'
To display lines containing laughing face emojis:
ug '[😀-😏]' emojis.txt
The same results are obtained using \x{hhhh}
to select a Unicode character
range:
ug '[\x{1F600}-\x{1F60F}]' emojis.txt
To display lines containing the names Gödel (or Goedel), Escher, or Bach:
ug 'G(ö|oe)del|Escher|Bach' GEB.txt wiki.txt
To search for lorem
in lower or upper case in a UTF-16 file that is marked
with a UTF-16 BOM:
ug -iw 'lorem' utf16lorem.txt
To search utf16lorem.txt when this file has no UTF-16 BOM, using --encoding
:
ug --encoding=UTF-16 -iw 'lorem' utf16lorem.txt
To search file spanish-iso.txt
encoded in ISO-8859-1:
ug --encoding=ISO-8859-1 -w 'año' spanish-iso.txt
Archives (cpio, jar, pax, tar, zip and 7z) are searched with option -z
.
Regular files in an archive that match are output with the archive pathnames
enclosed in {
and }
braces. Supported tar formats are v7, ustar, gnu,
oldgnu, and pax. Supported cpio formats are odc, newc, and crc. Not supported
is the obsolete non-portable old binary cpio format. Archive formats cpio,
tar, and pax are automatically recognized with option -z
based on their
content, independent of their filename suffix.
By default, uncompressed archives stored within zip archives are also searched: all cpio, pax, and tar files stored in zip and 7z archives are automatically recognized and searched. However, by default, compressed files stored within archives are not recognized, e.g. zip files stored within tar files are not searched but rather all compressed files and archives are searched as if they are binary files without decompressing them.
Specify --zmax=NUM
to search archives that contain compressed files and
archives for up to NUM
levels deep. The value of NUM
may range from 1 to
99 for up to 99 decompression and de-archiving steps to expand up to 99 nested
archives. Larger --zmax=NUM
values degrade performance. It is unlikely you
will ever need 99 as --zmax=2
suffices for most practical use cases, such as
searching zip files stored in tar files.
When option -z
is used with options -g
, -O
, -M
, or -t
, archives and
compressed and uncompressed files that match the filename selection criteria
(glob, extension, magic bytes, or file type) are searched only. For example,
ugrep -r -z -tc++
searches C++ files such as main.cpp
and zip and tar
archives that contain C++ files such as main.cpp
. Also included in the
search are compressed C++ files such as main.cpp.gz
and main.cpp.xz
when
present. Also any cpio, pax, tar, zip and 7z archives when present are
searched for C++ files that they contain, such as main.cpp
. Use option
--stats
to see a list of the glob patterns applied to filter file pathnames
in the recursive search and when searching archive contents.
When option -z
is used with options -g
, -O
, -M
, or -t
to search cpio,
jar, pax, tar, zip and 7z archives, archived files that match the filename
selection criteria are searched only.
The gzip, compress, zip, bzip2, xz, and zstd formats are automatically
detected, which is useful when reading compressed data from standard input,
e.g. input redirected from a pipe. Other compression formats require a
filename suffix: .lzma
for lzma, .lz4
for lz4, .br
for brotli and .bz3
for bzip3. Also the compressed tar archive shorthands .taz
, .tgz
and
.tpz
for gzip, .tbz
, .tbz2
, .tb2
, and .tz2
for bzip2, .tlz
for
lzma, .txz
for xz, and .tzst
for zstd are recognized. To search these
formats with ugrep from standard input, use option --label='stdin.bz2'
for
bzip2, --label='stdin.lzma'
for lzma, --label='stdin.lz4
for lz4 and so on.
The name stdin
is arbitrary and may be omitted:
format | filename suffix | tar/pax archive short suffix | suffix required? | detect on stdin | library |
---|---|---|---|---|---|
gzip | .gz | .taz , .tgz , .tpz | no | automatic | libz |
compress | .Z | .taZ , .tZ | no | automatic | built-in |
zip | .zip , .zipx , .ZIP | no | automatic | libz | |
bzip2 | .bz , .bz2 , .bzip2 | .tb2 , .tbz , .tbz2 , .tz2 | no | automatic | libbz2 |
xz | .xz | .txz | no | automatic | liblzma |
zstd | .zst , .zstd | .tzst | no | automatic | libzstd |
7zip | .7z | yes | --label=.7z | built-in | |
brotli | .br | yes | --label=.br | libbrotlidec | |
bzip3 | .bz3 | yes | --label=.bz3 | libbzip3 | |
lzma | .lzma | .tlz | yes | --label=.lzma | liblzma |
lz4 | .lz4 | yes | --label=.lz4 | liblz4 |
The gzip, bzip2, xz, lz4 and zstd formats support concatenated compressed files. Concatenated compressed files are searched as one single file.
Supported zip compression methods are stored (0), deflate (8), bzip2 (12), lzma (14), xz (95) and zstd (93). The bzip2, lzma, xz and zstd methods require ugrep to be compiled with the corresponding compression libraries.
Searching encrypted zip archives is not supported (perhaps in future releases, depending on requests for enhancements).
Searching 7zip archives takes a lot more RAM and more time compared to other
methods. The 7zip LZMA SDK implementation does not support streaming,
requiring a physical seekable 7z file. This means that 7z files cannot be
searched when nested within archives. Best is to avoid 7zip. Support for 7zip
can be disabled with ./build.sh --disable-7zip
to build ugrep.
Option -z
uses threads for task parallelism to speed up searching larger
files by running the decompressor concurrently with a search of the
decompressed stream.
To list all non-empty files stored in a package.zip
archive, including the
contents of all cpio, pax, tar, zip and 7z files that are stored in it:
ug --zmax=2 -z -l '' package.zip
Same, but only list the Python source code files, including scripts that invoke
Python, with option -tPython
(ugrep -tlist
for details):
ug --zmax=2 -z -l -tPython '' package.zip
To search Python applications distributed as a tar file with their dependencies
includes as wheels (zip files with Python code), searching for the word
my_class
in app.tgz
:
ug --zmax=2 -z -tPython -w my_class app.tgz
To recursively search C++ files including compressed files for the word
my_function
, while skipping C and C++ comments:
ug -z -r -tc++ -Fw my_function -f cpp/zap_comments
To search lzma, lz4, brotli, and bzip3 compressed data on standard input,
option --label
may be used to specify the extension corresponding to the
compression format to force decompression when the bzip2 extension is not
available to ugrep, for example:
cat myfile.lz4 | ugrep -z --label='stdin.lz4' 'xyz'
To search file main.cpp
in project.zip
for TODO
and FIXME
lines:
ug -z -g main.cpp -w -e 'TODO' -e 'FIXME' project.zip
To search tarball project.tar.gz
for C++ files with TODO
and FIXME
lines:
ug -z -tc++ -w -e 'TODO' -e 'FIXME' project.tar.gz
To search files matching the glob *.txt
in project.zip
for the word
license
in any case (note that the -g
glob argument must be quoted):
ug -z -g '*.txt' -w -i 'license' project.zip
To display and page through all C++ files in tarball project.tgz
:
ug --pager -z -tc++ '' project.tgz
To list the files matching the gitignore-style glob /**/projects/project1.*
in projects.tgz
, by selecting files containing in the archive the text
December 12
:
ug -z -l -g '/**/projects/project1.*' -F 'December 12' projects.tgz
To view the META-INF/MANIFEST.MF data in a jar file with -Ojar
and -OMF
to
select the jar file and the MF file therein (-Ojar
is required, otherwise the
jar file will be skipped though we could read it from standard input instead):
ug -z -h -OMF,jar '' my.jar
To extract C++ files that contain FIXME
from project.tgz
, we use -m1
with --format="'%z '"
to generate a space-separated list of pathnames of file
located in the archive that match the word FIXME
:
tar xzf project.tgz `ugrep -z -l -tc++ --format='%z ' -w FIXME project.tgz`
To perform a depth-first search with find
, then use cpio
and ugrep
to
search the files:
find . -depth -print | cpio -o | ugrep -z 'xyz'
pdftotext
to convert pdf to textantiword
to convert doc to textpandoc
to convert .docx, .epub, and other document
formatsexiftool
to read meta information
embedded in image and video media formats.soffice
to convert office documentscsvkit
to convert spreadsheetsopenssl
to
convert certificates and key files to text and other formatsThe ugrep+
and ug+
commands use the pdftotext
, antiword
, pandoc
and
exiftool
filters, when installed, to search pdfs, documents, e-books, and
image metadata.
Also decompressors may be used as filter utilities, such as unzip
, gunzip
,
bunzip2
, unlzma
, unxz
, lzop
and 7z
that decompress files to standard
output when option --stdout
is specified. For example:
ug --filter='lzo:lzop -d --stdout -' ...
ug --filter='gz:gunzip -d --stdout -' ...
ug --filter='7z:7z x -so %' ...
The --filter='lzo:lzop -d --stdout -'
option decompresses files with
extension lzo
to standard output with --stdout
with the compressed stream
being read from standard input with -
. The --filter='7z:7z x -so -si
option decompresses files with extension 7z
to standard output -so
while
reading standard input -si
with the compressed file contents.
Note that ugrep option -z
is typically faster to search compressed files
compared to --filter
.
The --filter
option may also be used to run a user-defined shell script to
filter files. For example, to invoke an action depending on the filename
extension of the %
argument. Another use case is to pass a file to more than
one filter, which can be accomplished with a shell script containing the line
tool1 $1; tool2 $1
. This filters the file argument $1
with tool1
followed by tool2
to produce combined output to search for pattern matches.
Likewise, we can use a script with the line tool1 $1 | tool2
to stack two
filters tool1
and tool2
.
The --filter
option may also be used as a predicate to skip certain files
from the search. As the most basic example, consider the false
utility that
exits with a nonzero exit code without reading input or producing output.
Therefore, --filter='swp: false'
skips all .swp
files from recursive
searches. The same can be done more efficiently with -O^swp
. However,
the --filter
option could invoke a script that determines if the filename
passed as a %
argument meets certain constraints. If the constraint is met
the script copies standard input to standard output with cat
. If not, the
script exits.
Warning: option --filter
should not be used with utilities that modify
files. Otherwise searches may be unpredicatable. In the worst case files may
be lost, for example when the specified utility replaces or deletes the file
passed to the command with --filter
option %
.
To recursively search files including PDF files in the working directory
without recursing into subdirectories (with -1
), for matches of drink me
using the pdftotext
filter to convert PDF to text without preserving page
breaks:
ug -r -1 --filter='pdf:pdftotext -nopgbrk % -' 'drink me'
To recursively search text files for eat me
while converting non-printable
characters in .txt and .md files using the cat -v
filter:
ug -r -ttext --filter='txt,md:cat -v' 'eat me'
The same, but specifying the .txt and .md filters separately:
ug -r -ttext --filter='txt:cat -v, md:cat -v' 'eat me'
To search the first 8K of a text file:
ug --filter='txt:head -c 8192' 'eat me' wonderland.txt
To recursively search and list the files that contain the word Alice
,
including .docx and .epub documents using the pandoc
filter:
ug -rl -w --filter='docx,epub:pandoc --wrap=preserve -t plain % -o -' 'Alice'
Important: the pandoc
utility requires an input file and will not read
standard input. Option %
expands into the full pathname of the file to
search. The output format specified is markdown
, which is close enough to
text to be searched.
To recursively search and list the files that contain the word Alice
,
including .odt, .doc, .docx, .rtf, .xls, .xlsx, .ppt, .pptx documents using the
soffice
filter:
ug -rl -w --filter='odt,doc,docx,rtf,xls,xlsx,ppt,pptx:soffice --headless --cat %' 'Alice'
Important: the soffice
utility will not output any text when one or more
LibreOffice GUIs are open. Make sure to quit all LibreOffice apps first. This
looks like a bug, but the LibreOffice developers do not appear to fix this
any time soon (unless perhaps more people complain?). You can work around this
problem by specifying a specific user profile for soffice
with the following
semi-documented argument passed to soffice
:
-env:UserInstallation=file:///home/user/.libreoffice-alt
.
To recursively search and display rows of .csv, .xls, and .xlsx spreadsheets
that contain 10/6
using the in2csv
filter of csvkit:
ug -r -Ocsv,xls,xlsx --filter='xls,xlsx:in2csv %' '10/6'
To search .docx, .xlsx, and .pptx files converted to XML for a match with
10/6
using unzip
as a filter:
ug -lr -Odocx,xlsx,pptx --filter='docx,xlsx,pptx:unzip -p %' '10/6'
Important: unzipping docx, xlxs, pptx files produces extensive XML output
containing meta information and binary data such as images. By contrast,
ugrep option -z
with -Oxml
selects the XML components only:
ug -z -lr -Odocx,xlsx,pptx,xml '10/6'
Note: docx, xlsx, and pptx are zip files containing multiple components.
When selecting the XML components with option -Oxml
in docx, xlsx, and pptx
documents, we should also specify -Odocx,xlsx,pptx
to search these type of
files, otherwise these files will be ignored.
To recurssively search X509 certificate files for lines with Not After
(e.g.
to find expired certificates), using openssl
as a filter:
ug -r 'Not After' -Ocer,der,pem --filter='pem:openssl x509 -text,cer,crt,der:openssl x509 -text -inform der'
Note that openssl
warning messages are displayed on standard error. If
a file cannot be converted it is probably in a different format. This can
be resolved by writing a shell script that executes openssl
with options
based on the file content. Then write a script with ugrep --filter
.
To search PNG files by filename extension with -tpng
using exiftool
:
ug -r -i 'copyright' -tpng --filter='*:exiftool %'
Same, but also include files matching PNG "magic bytes" with -tPng
and
--filter-magic-label='+png:\x89png\x0d\x0a\x1a\x0a'
to select the png
filter:
ug -r -i 'copyright' -tPng --filter='png:exiftool %' --filter-magic-label='+png:\x89png\x0d\x0a\x1a\x0a'
Note that +png
overrides any filename extension match for --filter
.
Otherwise, without a +
, the filename extension, when present, takes priority
over labelled magic patterns to invoke the corresponding filter command.
The LABEL
used with --filter-magic-label
and --filter
has no specific
meaning; any name or string that does not contain a :
or ,
may be used.
To list all files containing a RPM signature, located in the rpm
directory and
recursively below (see for example
list of file signatures):
ug -RlU '\A\xed\xab\xee\xdb' rpm
To recursively search without following symlinks, while ignoring files and
directories ignored by .gitignore (when present), use option --ignore-files
.
Note that -r
is the default when no FILE arguments are specified, we use it
here to make the examples easier to follow.
ug -rl --ignore-files 'xyz'
Same, but includes hidden files with -.
rather than ignoring them:
ug -rl. --ignore-files 'xyz'
To recursively list all files that are not ignored by .gitignore (when present)
with --ignore-files
:
ug -rl --ignore-files ''
Same, but list shell scripts that are not ignored by .gitignore, when present:
ug -rl -tShell '' --ignore-files
To recursively list all files that are not ignored by .gitignore and are also
not excluded by .git/info/exclude
:
ug -rl '' --ignore-files --exclude-from=.git/info/exclude
Same, but by creating a symlink to .git/info/exclude
to make the exclusions
implicit:
ln -s .git/info/exclude .ignore
ug -rl '' --ignore-files --ignore-files=.ignore
Gitignore-style glob syntax and conventions:
pattern | matches |
---|---|
* | anything except / |
? | any one character except / |
[abc-e] | one character a ,b ,c ,d ,e |
[^abc-e] | one character not a ,b ,c ,d ,e ,/ |
[!abc-e] | one character not a ,b ,c ,d ,e ,/ |
/ | when used at the start of a glob, matches working directory |
**/ | zero or more directories |
/** | when at the end of a glob, matches everything after the / |
\? | a ? or any other character specified after the backslash |
When a glob pattern contains a path separator /
, the full pathname is
matched. Otherwise the basename of a file or directory is matched in recursive
searches. For example, *.h
matches foo.h
and bar/foo.h
. bar/*.h
matches bar/foo.h
but not foo.h
and not bar/bar/foo.h
.
When a glob pattern begins with a /
, files and directories are matched at the
working directory, not recursively. For example, use a leading /
to force
/*.h
to match foo.h
but not bar/foo.h
.
When a glob pattern ends with a /
, directories are matched instead of files,
same as --include-dir
.
When a glob starts with a !
as specified with -g!GLOB
, or specified in a
FILE
with --include-from=FILE
or --exclude-from=FILE
, it is negated.
To view a list of inclusions and exclusions that were applied to a search, use
option --stats
.
To list only readable files with names starting with foo
in the working
directory, that contain xyz
, without producing warning messages with -s
and
-l
:
ug -sl 'xyz' foo*
The same, but using deep recursion with inclusion constraints (note that
-g'/foo*
is the same as --include='/foo*'
and -g'/foo*/'
is the same as
--include-dir='/foo*'
, i.e. immediate subdirectories matching /foo*
only):
ug -rl 'xyz' -g'/foo*' -g'/foo*/'
Note that -r
is the default, we use it here to make the examples easier to
follow.
To exclude directory bak
located in the working directory:
ug -rl 'xyz' -g'^/bak/'
To exclude all directoies bak
at any directory level deep:
ug -rl 'xyz' -g'^bak/'
To only list files in the working directory and its subdirectory doc
,
that contain xyz
(note that -g'/doc/'
is the same as
--include-dir='/doc'
, i.e. immediate subdirectory doc
only):
ug -rl 'xyz' -g'/doc/'
To only list files that are on a subdirectory path doc
that includes
subdirectory html
anywhere, that contain xyz
:
ug -rl 'xyz' -g'doc/**/html/'
To only list files in the working directory and in the subdirectories doc
and doc/latest
but not below, that contain xyz
:
ug -rl 'xyz' -g'/doc/' -g'/doc/latest/'
To recursively list .cpp files in the working directory and any subdirectory
at any depth, that contain xyz
:
ug -rl 'xyz' -g'*.cpp'
The same, but using a .gitignore-style glob that matches pathnames (globs with
/
) instead of matching basenames (globs without /
) in the recursive search:
ug -rl 'xyz' -g'**/*.cpp'
Same, but using option -Ocpp
to match file name extensions:
ug -rl -Ocpp 'xyz'
To recursively list all files in the working directory and below that are not ignored by a specific .gitignore file:
ug -rl '' --exclude-from=.gitignore
To recursively list all files in the working directory and below that are not ignored by one or more .gitignore files, when any are present:
ug -rl '' --ignore-files
--color[=WHEN], --colour[=WHEN]
Mark up the matching text with the expression stored in the
GREP_COLOR or GREP_COLORS environment variable. The possible
values of WHEN can be `never', `always', or `auto', where `auto'
marks up matches only when output on a terminal. The default is
`auto'.
--colors=COLORS, --colours=COLORS
Use COLORS to mark up text. COLORS is 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 or `k'
(black), `r' (red), `g' (green), `y' (yellow), `b' (blue), `m'
(magenta), `c' (cyan), `w' (white), or leave 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 properties `n' (normal), `f' (faint), `h' (highlight), `i'
(invert), `u' (underline). Parameter `hl' enables file name
hyperlinks. Parameter `rv' reverses the `sl=' and `cx=' parameters
when option -v is specified. Selectively overrides GREP_COLORS.
Legacy grep single parameter codes may be specified, for example
--colors='7;32' or --colors=ig to set ms (match selected).
--tag[=TAG[,END]]
Disables colors to mark up matches with TAG. END marks the end of
a match if specified, otherwise TAG. The default is `___'.
--pager[=COMMAND]
When output is sent to the terminal, uses COMMAND to page through
the output. COMMAND defaults to environment variable PAGER when
defined or `less'. Enables --heading and --line-buffered.
--pretty[=WHEN]
When output is sent to a terminal, enables --color, --heading, -n,
--sort, --tree and -T when not explicitly disabled. WHEN can be
`never', `always', or `auto'. The default is `auto'.
--tree, -^
Output directories with matching files in a tree-like format for
option -c or --count, -l or --files-with-matches, -L or
--files-without-match. This option is enabled by --pretty when the
output is sent to a terminal.
To change the color palette, set the GREP_COLORS
environment variable or use
--colors=COLORS
. The value is a colon-separated list of ANSI SGR parameters
that defaults to cx=33:mt=1;31:fn=1;35:ln=1;32:cn=1;32:bn=1;32:se=36
:
param | result |
---|---|
sl= | selected lines |
cx= | context lines |
rv | Swaps the sl= and cx= capabilities when -v is specified |
mt= | matching text in any matching line |
ms= | matching text in a selected line. The substring mt= by default |
mc= | matching text in a context line. The substring mt= by default |
fn= | file names |
ln= | line numbers |
cn= | column numbers |
bn= | byte offsets |
se= | separators |
hl | hyperlink file names, same as --hyperlink |
qp= | TUI prompt |
qe= | TUI errors |
qr= | TUI regex |
qm= | TUI regex meta characters |
ql= | TUI regex lists and literals |
qb= | TUI regex braces |
Multiple SGR codes may be specified for a single parameter when separated by a
semicolon, e.g. mt=1;31
specifies bright red. The following SGR codes are
available on most color terminals:
code | c | effect | code | c | effect |
---|---|---|---|---|---|
0 | n | normal font and color | 2 | f | faint (not widely supported) |
1 | h | highlighted bold font | 21 | H | highlighted bold off |
4 | u | underline | 24 | U | underline off |
7 | i | invert video | 27 | I | invert off |
30 | k | black text | 90 | +k | bright gray text |
31 | r | red text | 91 | +r | bright red text |
32 | g | green text | 92 | +g | bright green text |
33 | y | yellow text | 93 | +y | bright yellow text |
34 | b | blue text | 94 | +b | bright blue text |
35 | m | magenta text | 95 | +m | bright magenta text |
36 | c | cyan text | 96 | +c | bright cyan text |
37 | w | white text | 97 | +w | bright white text |
40 | K | black background | 100 | +K | bright gray background |
41 | R | dark red background | 101 | +R | bright red background |
42 | G | dark green background | 102 | +G | bright green background |
43 | Y | dark yellow backgrounda | 103 | +Y | bright yellow background |
44 | B | dark blue background | 104 | +B | bright blue background |
45 |
For quick and easy color specification, the corresponding single-letter color names may be used in place of numeric SGR codes and semicolons are not required to separate color names. Color names and numeric codes may be mixed.
For example, to display matches in underlined bright green on bright selected lines, aiding in visualizing white space in matches and file names:
export GREP_COLORS='sl=1:cx=33:ms=1;4;32;100:mc=1;4;32:fn=1;32;100:ln=1;32:cn=1;32:bn=1;32:se=36'
The same, but with single-letter color names:
export GREP_COLORS='sl=h:cx=y:ms=hug+K:mc=hug:fn=hg+K:ln=hg:cn=hg:bn=hg:se=c'
Another color scheme that works well:
export GREP_COLORS='cx=hb:ms=hiy:mc=hic:fn=hi+y+K:ln=hg:cn=hg:bn=hg:se='
Modern Windows command interpreters support ANSI escape codes. Named or
numeric colors can be set with SET GREP_COLORS
, for example:
SET GREP_COLORS=sl=1;37:cx=33:mt=1;31:fn=1;35:ln=1;32:cn=1;32:bn=1;32:se=36
To disable colors on Windows:
SET GREP_COLORS=""
Color intensities may differ per platform and per terminal program used, which affects readability.
Option -y
outputs every line of input, including non-matching lines as
context. The use of color helps distinguish matches from non-matching context.
To copy silver searcher's color palette:
export GREP_COLORS='mt=30;43:fn=1;32:ln=1;33:cn=1;33:bn=1;33'
To produce color-highlighted results (--color
is redundance since it is the
default):
ug --color -r -n -k -tc++ 'FIXME.*'
To page through the results with pager (less -R
by default):
ug --pager -r -n -k -tc++ 'FIXME'
To display a hexdump of a zip file itself (i.e. without decompressing), with
color-highlighted matches of the zip magic bytes PK\x03\x04
(--color
is
redundant since it is the default):
ug --color -y -UX 'PK\x03\x04' some.zip
To use predefined patterns to list all #include
and #define
in C++ files:
ug --pretty -r -n -tc++ -f c++/includes -f c++/defines
Same, but overriding the color of matches as inverted yellow (reverse video)
and headings with yellow on blue using --pretty
:
ug --pretty --colors="ms=yi:fn=hyB" -r -n -tc++ -f c++/includes -f c++/defines
To list all #define FOO...
macros in C++ files, color-highlighted:
ug --color=always -r -n -tc++ -f c++/defines | ug 'FOO.*'
Same, but restricted to .cpp
files only:
ug --color=always -r -n -Ocpp -f c++/defines | ug 'FOO.*'
To search tarballs for matching names of PDF files (assuming bash is our shell):
for tb in *.tar *.tar.gz *.tgz; do echo "$tb"; tar tfz "$tb" | ugrep '.*\.pdf$'; done
--format=FORMAT
Output FORMAT-formatted matches. For example --format='%f:%n:%O%~'
outputs matching lines `%O' with filename `%f` and line number `%n'
followed by a newline `%~'. If -P is specified, FORMAT may include
`%1' to `%9', `%[NUM]#' and `%[NAME]#' to output group captures. A
`%%' outputs `%'. See `ugrep --help format' and `man ugrep'
section FORMAT for details. When option -o is specified, option -u
is also enabled. Context options -A, -B, -C and -y are ignored.
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression.
Use option -P
to use group captures and backreferences. Capturing groups in
regex patterns are parenthesized expressions (pattern)
. The first group is
referenced in FORMAT
by %1
, the second by %2
and so on. Named captures
are of the form (?pattern)
and are referenced in FORMAT
by
%[NAME]#
.
The following output formatting options may be used. The FORMAT
string
%
-fields are listed in a table further below:
option | result |
---|---|
--format-begin=FORMAT | FORMAT beginning the search |
--format-open=FORMAT | FORMAT opening a file and a match was found |
--format=FORMAT | FORMAT for each match in a file |
--format-close=FORMAT | FORMAT closing a file and a match was found |
--format-end=FORMAT | FORMAT ending the search |
The following tables show the formatting options corresponding to --csv
,
--json
, and --xml
.
--csv
option | format string (within quotes) |
---|---|
--format-open | '%+' |
--format | '%[,]$%H%N%K%B%V%~%u' |
--json
option | format string (within quotes) |
---|---|
--format-begin | '[' |
--format-open | '%,%~ {%~ %[,%~ ]$%["file": ]H"matches": [' |
--format | '%,%~ { %[, ]$%["line": ]N%["column": ]K%["offset": ]B"match": %J }%u' |
--format-close | '%~ ]%~ }' |
--format-end | '%~]%~' |
--xml
option | format string (within quotes) |
---|---|
--format-begin | '%~' |
--format-open | ' |
%, | 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 %[│]> |
%S | if not the first match: separator, see also %[SEP]$ |
%[TEXT]S | if not the first match: TEXT and separator, see also %[SEP]$ |
%s | the separator, see also %[TEXT]S and %[SEP]$ |
%R | if option --break or --heading is used: a newline |
%m | the number of matches, sequential (or number of matching files with --format-end ) |
%M | the number of matching lines (or number of matching files with --format-end ) |
%O | the matching line is output as is (a raw string of bytes) |
%o | the match is output as is (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 |
Note:
%~
is
explicitly specified in the format string.-o
changes the output of the %O
and %Q
fields to output the
match only.-c
, -l
and -o
change the output of %C
, %J
, %X
and %Y
accordingly[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, when option -H
is used.%n
are padded with spaces when %{width}n
is
specified.%O
are cut to width when %{width}O
is
specified or when %{-width}O
is specified to cut from the end of the line.%{-width}o
or %{+width}o
is specified for match fields such as %o
,
where %{width}o
without a +/- sign cuts the match to the specified width.%[SEP]$
and %u
are switches and do not write anything to the
output.%F
, %H
, %N
, %K
, %B
, %S
, and %G
may be
changed by preceding the field with a %[SEP]$
. When [SEP]
is not
provided, reverts the separator to the default separator or the separator
specified by --separator
.%u
is found anywhere in the specified format string,
matching lines are output only once unless option -u
, --ungroup
is used or when a newline is matched.%g
corresponds to the index of the
sub-pattern matched among the alternations in the pattern when option -P
is
not used. For example foo|bar
matches foo
with index 1 and bar
with
index 2. With option -P
, the index corresponds to the number of the first
group captured in the specified pattern.To output matching lines faster by omitting the header output and binary match
checks, using --format
with field %O
(output matching line as is) and field
%~
(output newline):
ug --format='%O%~' 'href=' index.html
Same, but also displaying the line and column numbers:
ug --format='%n%k: %O%~' 'href=' index.html
Same, but display a line at most once when matching multiple patterns, unless
option -u
is used:
ug --format='%u%n%k: %O%~' 'href=' index.html
To string together a list of unique line numbers of matches, separated by
commas with field %,
:
ug --format='%u%,%n' 'href=' index.html
To output the matching part of a line only with field %o
(or option -o
with
field %O
):
ug --format='%o%~' "href=[\"'][^\"'][\"']" index.html
To string together the pattern matches as CSV-formatted strings with field %v
separated by commas with field %,
:
ug --format='%,%v' "href=[\"'][^\"'][\"']" index.html
To output matches in CSV (comma-separated values), the same as option --csv
(works with options -H
, -n
, -k
, -b
to add CSV values):
ug --format='"%[,]$%H%N%K%B%V%~%u"' 'href=' index.html
To output matches in AckMate format:
ug --format=":%f%~%n;%k %w:%O%~" 'href=' index.html
To output the sub-pattern indices 1, 2, and 3 on the left to the match for the
three patterns foo
, bar
, and baz
in file foobar.txt
:
ug --format='%g: %o%~' 'foo|bar|baz' foobar.txt
Same, but using a file foos
containing three lines with foo
, bar
, and
baz
, where option -F
is used to match strings instead of regex:
ug -F -f foos --format='%g: %o%~' foobar.txt
To output one
, two
, and a word
for the sub-patterns [fF]oo
, [bB]ar
,
and any other word \w+
, respectively, using argument [one|two|a word]
with
field %g
indexed by sub-pattern (or group captures with option -P
):
ug --format='%[one|two|a word]g%~' '([fF]oo)|([bB]ar)|(\w+)' foobar.txt
To output a list of group capture indices with %G
separated by the word and
instead of the default colons with %[ and ]$
, followed by the matching line:
ug -P --format='%[ and ]$%G%$%s%O%~' '(foo)|(ba((r)|(z)))' foobar.txt
Same, but showing names instead of numbers:
ug -P --format='%[ and ]$%[foo|ba|r|z]G%$%s%O%~' '(foo)|(ba(?:(r)|(z)))' foobar.txt
Note that option -P
is required for general use of group captures for
sub-patterns. Named sub-pattern matches may be used with PCRE2 and shown in
the output:
ug -P --format='%[ and ]$%G%$%s%O%~' '(?Pfoo)|(?Pba(?:(?Pr)|(?Pz)))' foobar.txt
See customized output with --format for details on the FORMAT
fields.
For option -o
, the replacement is not automatically followed by a newline to
allow for more flexibility in replacements. To output a newline, use %~
in
the FORMAT
string.
Use option -P
to use group captures and backreferences. Capturing groups in
regex patterns are parenthesized expressions (pattern)
and the first is
referenced in FORMAT
by %1
, the second by %2
and so on. Named captures
are of the form (?pattern)
and are referenced in FORMAT
by
%[NAME]#
.
To display pattern matches with their sequential match number using
--replace='%m:%o'
where %m
is the sequential match number and %o
is the
pattern matched:
ug --replace='%m:%o' pattern myfile.txt
Same, but passing the file through with option -y
, while applying the
replacements to the output:
ug -y --replace='%m:%o' pattern myfile.txt
To extract table cells from an HTML file using Perl matching (-P
) to support
group captures with lazy quantifier (.*?)
, and translate the matches to a
comma-separated list with format %,%1
(conditional comma and group capture):
ug -P -o '(.*?)' --replace='%,%1' index.html
Same, but using --format='%,%1'
instead and we do not need -o
(note that
--replace
color-highlights matches shown on a terminal but --format
does
not):
ug -P '(.*?)' --format='%,%1' index.html
Same, but displaying the formatted matches line-by-line, with --replace
or
with --format
:
ug -P -o '(.*?)' --replace='%,%1' index.html
ug -P '(.*?)' --format='%1%~' index.html
To collect all href
URLs from all HTML and PHP files down the working
directory, then sort them:
ug -r -thtml,php -P '<[^<>]+href\h*=\h*.([^\x27"]+).' --format='%1%~' | sort -u
Same, but much easier by using the predefined html/href
pattern:
ug -r -thtml,php -P -f html/href --format='%1%~' | sort -u
Same, but in this case select `
toggle ugrep command-line option corresponding to key , same as Alt-key |
Ctrl-R F4 | jump to bookmark |
Ctrl-S | jump to the next dir/file/context |
Ctrl-T F5 | toggle split screen (--split starts a split-screen TUI) |
Ctrl-U | delete before cursor |
Ctrl-V | verbatim character |
Ctrl-W | jump back one dir/file/context |
Ctrl-X F3 | set bookmark |
Ctrl-Y F2 | view or edit the file shown at the top of the screen |
Ctrl-Z F1 | view help and options |
Ctrl-^ | chdir back to the starting working directory |
Ctrl-] | toggle color/mono |
Ctrl-\ | terminate process |
M |
dark magenta background |
105 |
+M |
bright magenta background |
46 | C | dark cyan background | 106 | +C | bright cyan background |
47 | W | dark white background | 107 | +W | bright white background |
%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 |
%Y | the matching line formatted in hex |
%y | the match formatted in hex |
%A | byte range of the match in hex |
%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 -u is used |
%[hhhh]U | U+hhhh Unicode code point |
%[CODE]= | a color CODE, such as ms , see colors |
%= | turn color off |
%1 %2 ... %9 | the first regex group capture of the match, and so on up to group %9 , requires option -P |
%[NUM]# | the group capture NUM ; requires option -P |
%[NUM]b | the byte offset of the group capture NUM ; requires option -P |
%[NUM]e | the ending byte offset of the group capture NUM ; requires option -P |
%[NUM]d | the byte length of the group capture NUM ; requires option -P |
%[NUM]j | the group capture NUM as JSON; requires option -P |
%[NUM]q | the group capture NUM quoted; requires option -P |
%[NUM]x | the group capture NUM as XML; requires option -P |
%[NUM]y | the group capture NUM as hex; requires option -P |
%[NUM]v | the group capture NUM as CSV; requires option -P |
%[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 . |
%[NUM1|NUM2|...]e | the ending byte offset of the first group capture NUM that matched; requires option -P . |
%[NUM1|NUM2|...]d | the byte length of the first group capture NUM that matched; requires option -P . |
%[NUM1|NUM2|...]j | the first group capture NUM that matched, as JSON; requires option -P |
%[NUM1|NUM2|...]q | the first group capture NUM that matched, quoted; requires option -P |
%[NUM1|NUM2|...]x | the first group capture NUM that matched, as XML; requires option -P |
%[NUM1|NUM2|...]y | the first group capture NUM that matched, as hex; requires option -P |
%[NUM1|NUM2|...]v | the first group capture NUM that matched, as CSV; requires option -P |
%[NAME]# | the NAME d group capture; requires option -P and capturing pattern (?PATTERN) |
%[NAME]b | the byte offset of the NAME d group capture; requires option -P and capturing pattern (?PATTERN) . |
%[NAME]e | the ending byte offset of the NAME d group capture; requires option -P and capturing pattern (?PATTERN) . |
%[NAME]d | the byte length of the NAME d group capture; requires option -P and capturing pattern (?PATTERN) . |
%[NAME]j | the NAME d group capture as JSON; requires option -P and capturing pattern (?PATTERN) |
%[NAME]q | the NAME d group capture quoted; requires option -P and capturing pattern (?PATTERN) |
%[NAME]x | the NAME d group capture as XML; requires option -P and capturing pattern (?PATTERN) |
%[NAME]y | the NAME d group capture as hex; requires option -P and capturing pattern (?PATTERN) |
%[NAME]v | the NAME d group capture as CSV; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]# | the first NAME d group capture that matched; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]b | the byte offset of the first NAME d group capture that matched; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]e | the ending byte offset of the first NAME d group capture that matched; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]d | the byte length of the first NAME d group capture that matched; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]j | the first NAME d group capture that matched, as JSON; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]q | the first NAME d group capture that matched, quoted; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]x | the first NAME d group capture that matched, as XML; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]y | the first NAME d group capture that matched, as hex; requires option -P and capturing pattern (?PATTERN) |
%[NAME1|NAME2|...]v | the first NAME d group capture that matched, as CSV; requires option -P and capturing pattern (?PATTERN) |
%G | list of group capture indices/names of the match (see note) |
%[TEXT1|TEXT2|...]G | list of TEXT indexed by group capture indices that matched; requires option -P |
%g | the group capture index of the match or 1 (see note) |
%[TEXT1|TEXT2|...]g | the first TEXT indexed by the first group capture index that matched; requires option -P |
%[TEXT1|TEXT2|...]G
and
%[TEXT1|TEXT2|...]g
should correspond to the group capture index (see the
note above), i.e. TEXT1
is output for index 1, TEXT2
is output for index
2, and so on. If the list is too short, the index value is output or the
name of a named group capture is output.-T
and --pretty
add right-justifying spacing to fields %N
and
%K
if no leading [TEXT]
part is specified.%+
may be used in --format-open
to output the pathname heading and
a newline break, respectively. Field %+
suppresses %a
, %F
, %f
,
%H
, %h
and %p
output.