FIELD NOTES / UNIX & LINUXNew tools on weekdays. Beyond the man page.
$fzf

fzf: put a deliberate choice in the middle of a pipeline

Turn ordinary command output into an interactive selector, then preserve the boundaries between matching, previewing, and acting.

THE DEEP DIVE19 MIN READ
01

Start with records, not files

fzf reads candidate records, lets you narrow and choose them in a terminal interface, and writes your selection to standard output. A record is normally one line. The records can be service names, build identifiers, paths, or anything else a command can print. Reach for it when a script needs a human decision among many candidates, not when you already have an exact automated rule.

Here is the whole model with three service names. Run it in an interactive Bash terminal with fzf installed. printf repeats the %s\n format for each following argument: %s prints a string, and \n ends its line. The pipe connects that output to fzf's input. The quotes keep the format intact for printf; the printf article explains the distinction between format and data.

TERMINALBASH — DISPOSABLE LAB
printf '%s\n' api cache worker | fzf
TERMINALEXPECTED OUTPUT
worker

Output, after typing wrk and pressing Enter: Fuzzy matching means the query's letters can appear in order without being adjacent: w, r, and k occur in worker. Use the arrow keys to move the focused row and Enter to accept it. Escape or Ctrl-C cancels. The interface uses the terminal; the accepted record goes to standard output, so another command can consume it. Fzf does not search file contents simply because a candidate happens to be a pathname. We will build a configuration-file selector, then add previews, multiple selections, and a replaceable producer without losing that distinction.

02

Build a private configuration lab

These examples target upstream fzf 0.75.0, Bash 5.2, and GNU/Linux helpers: Findutils 4.9, Coreutils 9.4, sed 4.9, and grep 3.11. The official 0.75.0 release was published November 7, 2026. Distribution packages may backport fixes or ship older interfaces; check your package's documentation. The --version flag prints the local fzf version.

Start a clean interactive child Bash with the first line, then paste the remaining lines at its new prompt. --noprofile and --norc skip Bash startup files; -i requests an interactive shell. This avoids loading personal shell customizations for the lab. unset removes inherited fzf default-option settings, including the optional options-file path. export SHELL=/bin/bash tells fzf which shell to use for its command hooks. None of this edits your startup files.

mktemp -d creates a fresh private temporary directory and prints its path. The $(...) command substitution captures that path in fzf_lab. The double quotes preserve it as one argument to cd, which changes the child shell's working directory. Every dependent setup step is connected with &&, so a failed step prevents later file writes. The > redirects create three synthetic configuration files. The \n escapes in their printf formats produce actual newlines. Remain in this directory for the rest of the lab.

TERMINALBASH — DISPOSABLE LAB
bash --noprofile --norc -i
unset FZF_DEFAULT_OPTS FZF_DEFAULT_OPTS_FILE FZF_DEFAULT_COMMAND
export SHELL=/bin/bash
fzf --version
fzf_lab=$(mktemp -d) &&
cd "$fzf_lab" &&
printf 'service=api\nlevel=ERROR\n' > api.conf &&
printf 'service=cache\nlevel=INFO\n' > cache.conf &&
printf 'service=worker\nlevel=WARN\n' > 'worker notes.conf' &&
printf 'lab ready\n'
TERMINALOBSERVED OUTPUT
0.75.0 (c7bf2b8e)
lab ready

Observed output on the tested build, excluding the new shell prompt: Continue only after lab ready appears. The temporary path varies and the files are deliberately retained for inspection. Leave the child shell with exit when finished. These are ordinary unprivileged files: no service is started, no system configuration is read, and no cleanup command targets a broad directory.

03

Separate fuzzy convenience from a matching rule

Fuzzy ranking is useful for human navigation but is not an exact predicate. The --filter option takes a query and runs without the interactive interface, printing all matching records. It gives us a reproducible way to inspect the matching rule. Here pc matches api-cache even though the letters are separated. --exact changes ordinary search terms to contiguous matches, so only the record actually containing pc remains.

TERMINALBASH — DISPOSABLE LAB
printf '%s\n' api-cache pc worker | fzf --filter pc
printf '%s\n' api-cache pc worker | fzf --exact --filter pc
TERMINALEXPECTED OUTPUT
pc
api-cache
pc

Expected output, with the first two lines from the first command: Exact means a contiguous term, not whole-record equality. A query of api can still match api-cache. Fzf's default extended-search syntax also interprets spaces as separate terms and recognizes operators such as ! for negation and ^ or $ for boundaries; it is not a general regular-expression engine. Single-quoting a command-line query protects it from Bash but does not disable fzf's own query language. For scripted validation, use a tool and predicate that express the exact contract. In interactive use, fzf's ranking is a suggestion about relevance, not evidence that the first match is the right target.

04

Treat cancellation as a result

The upstream manual defines status 0 for a normal successful match, 1 for no match, 2 for an error, and 130 for interruption. A wrapper should not blindly run an action after the chooser disappears. The following noninteractive example makes the no-match path visible without requiring a timed keypress.

if branches on a command's exit status: zero takes the then branch; nonzero takes else. The assignment captures fzf's standard output in choice and carries the command substitution's status. Save $?, the immediately preceding status, before running another command. The quoted variable in printf remains one data argument. This uses only a single newline-free identifier; command substitution removes trailing newlines and is not a container for arbitrary pathname streams.

TERMINALBASH — DISPOSABLE LAB
if choice=$(printf '%s\n' api cache worker | fzf --filter missing); then
  printf 'chosen=%s\n' "$choice"
else
  status=$?
  printf 'no selection: status=%s\n' "$status"
fi
TERMINALEXPECTED OUTPUT
no selection: status=1

Expected output: Replace the filter invocation with an interactive fzf and the same conditional can distinguish acceptance from cancellation or error. This checks fzf's status, not every upstream producer: Bash normally reports the last command's status for a pipeline. For an important inventory, finish the producer into a checked temporary file before selection, or explicitly inspect pipeline statuses. An empty or partial candidate list is not proof that the underlying system has no matching objects.

05

Preview the focused file without treating its name as code

Now the input records are the three fixture paths. find . -maxdepth 1 -type f -name '*.conf' -print starts at the current directory, limits traversal to immediate children, keeps regular files whose names match the quoted pattern, and prints each pathname. The shell leaves the pattern for find to interpret. The find article develops these selection tests. These three names contain spaces but no newlines, so line framing is adequate for this first example.

The --preview option takes a command template. Fzf substitutes {} with the focused record, shell-quoted, then runs the command through the configured shell. Leave the placeholder unquoted inside the template: fzf supplies its argument quoting. The outer single quotes protect the template from the initial Bash parse. Do not replace the placeholder with raw substitution or add eval around selected data.

The preview uses sed -n 1,20p -- {}. Sed reads the selected file; -n disables automatic printing, 1,20p prints lines one through twenty, and -- ends sed's options before the filename. Spaces, quotes, and option-like names are separate concerns: shell quoting preserves one argument, while -- prevents that argument from becoming a sed option. The command reads the entire file to end of input even though it prints only twenty lines; this is a display bound, not a read-size limit.

TERMINALBASH — DISPOSABLE LAB
find . -maxdepth 1 -type f -name '*.conf' -print |
  fzf --preview 'sed -n 1,20p -- {}'
TERMINALEXPECTED OUTPUT
./api.conf

Output, after typing api and pressing Enter: Before acceptance, the preview shows service=api and level=ERROR from the focused file. Moving focus can launch another preview; no Enter press is required. Keep preview commands read-only and cheap, because merely browsing runs them repeatedly. Placeholder quoting prevents a filename from becoming shell syntax here; it does not validate the file, constrain its contents, prevent symlink races, or make an arbitrary preview program safe. This plain-text preview is suitable for our synthetic configs, not unknown binary evidence.

06

Keep multiple pathnames intact all the way through

A Unix filename may contain a newline. Quoting a correctly received pathname cannot repair a stream that already split it into two records. Add two more harmless configs: one name contains an apostrophe, and one contains a literal newline. Bash's $'...' quoting interprets \n when constructing the latter filename. The content format still produces ordinary newline-terminated text. The setup steps are guarded as before.

Find's -print0 ends each pathname with NUL, a zero byte that cannot occur inside a Unix pathname. Fzf's --read0 reads those boundaries; --print0 preserves them in the output. --multi permits marking several rows: Tab toggles the focused row and moves onward; Shift-Tab toggles and moves backward. Enter accepts the marked set, or the focused item if none is marked.

The receiving GNU xargs -0 -r understands NUL-delimited input and does not run the command for an empty selection. It appends the selected paths as separate arguments to wc -c --: wc counts bytes, and -- ends its options. This is a harmless read-only action, not a deletion recipe. The xargs article explains argument transport and batching. A newline after a pipe continues the same pipeline; these indented lines are not independent commands.

TERMINALBASH — DISPOSABLE LAB
printf 'mode=quoted\n' > "quote's.conf" &&
printf 'mode=multiline\n' > $'line\nbreak.conf' &&
find . -maxdepth 1 -type f -name '*.conf' -print0 |
  fzf --read0 --multi --print0 --preview 'sed -n 1,20p -- {}' |
  xargs -0 -r wc -c --

Expected observation: selecting the apostrophe-named file alone produces a byte count of 12; selecting the newline-named file alone produces 15. Selecting several files produces per-file counts and, when passed together in one invocation, a total. Wc's displayed filename escaping can vary by output context; the important property is that each actual pathname arrived as one argument. The --read0 flag also allows multiline item display, so the newline name may occupy more than one screen row while remaining one record. NUL framing must survive every stage; do not squeeze the result into a Bash variable or switch back to line-oriented processing in the middle. The entire pipeline normally reports xargs's status, so it does not preserve fzf's cancellation code. It is appropriate here because an empty output causes no action and wc is read-only. A state-changing workflow needs explicit producer and selector status checks, a reviewed target set, and a separate confirmation policy.

07

Reload the producer, not just the screen

Once the list is open, new files are not automatically part of the original find output. A binding connects a key or event to an fzf action. --bind takes a comma-separated list; a colon separates each key from its action. Here Ctrl-R runs reload(...), replacing candidates with the new command's output. Ctrl-/ invokes toggle-preview, which hides or shows the preview pane. These are fzf-local bindings, not persistent changes to your shell.

The reload command uses the same NUL-producing find expression, matching --read0. Double quotes around *.conf belong to the child shell inside the single-quoted binding and keep find's pattern intact. With this input format, every future producer must also emit NUL-separated records.

TERMINALBASH — DISPOSABLE LAB
find . -maxdepth 1 -type f -name '*.conf' -print0 |
  fzf --read0 --preview 'sed -n 1,20p -- {}' \
    --bind 'ctrl-r:reload(find . -maxdepth 1 -type f -name "*.conf" -print0),ctrl-/:toggle-preview'

Expected observation: Ctrl-/ toggles the pane; Ctrl-R reruns find and refreshes the list. The backslash at the end of the fzf line escapes its newline so Bash continues that command. Enter still prints the selected pathname, now newline-terminated because this example does not request --print0 and has no downstream consumer. For a real pathname consumer, keep --print0 as in the preceding example. Reload is a separate child process, not a reread of an exhausted pipe. Its cost and failure behavior belong to the producer. The manual's asynchronous reload model lets fzf remain responsive while replacing the candidate list; do not interpret a transient empty or old view as a complete inventory. A fixed Ctrl-R refresh is often enough. Only move to query-driven reload when another search engine should own the matching rule.

08

Let another command answer the query

Suppose the question changes from “which filename?” to “which config contains this literal text?” Fzf need not perform that search. --disabled switches off its own matching, and --query ERROR seeds the input box with ERROR. A start event runs once when the interface starts; a change event runs when the query changes. Both reload the same grep producer. {q} substitutes the current query as a shell-quoted argument, including an empty string or punctuation.

GNU grep -F -l -Z -- {q} ./*.conf uses fixed-string matching (-F), prints only matching filenames (-l), and NUL-terminates those filenames (-Z). The -- ends options before the query, so a query beginning with a hyphen remains data. The child shell expands ./*.conf to the fixture files, preserving each pathname as an argument. The || test $? -eq 1 tail handles grep's expected no-match status: || runs its right side only when grep fails; $? expands immediately to grep's status before test runs, and -eq 1 numerically compares it with grep's no-match status. No match becomes a successful empty list, while a grep error remains a failed reload rather than silently becoming an empty success.

TERMINALBASH — DISPOSABLE LAB
fzf --read0 --disabled --query ERROR \
  --bind 'start:reload(grep -F -l -Z -- {q} ./*.conf || test $? -eq 1),change:reload(grep -F -l -Z -- {q} ./*.conf || test $? -eq 1)' \
  --preview 'sed -n 1,20p -- {}' < /dev/null
TERMINALEXPECTED OUTPUT
./api.conf

Output, after accepting the initial ERROR result: The < redirection supplies an empty input stream from /dev/null so no default file walker supplies the initial list. Reload provides the candidates. Type WARN to see worker notes.conf, or an absent string to get an empty list. An empty query matches every fixture file that contains a line. Here grep searches contents and fzf displays its answers; fuzzy filename ranking is intentionally disabled. Each query change can spawn another grep process, so this small lab is not a scalable search architecture. Use a bounded scope and an appropriate backend for large trees. Selecting a result does not establish that the rest of the file or directory passed an audit.

09

Inspect unfamiliar bytes without interpreting them as display instructions

During an authorized review, a selector can be a convenient index into supplied evidence. It is not a reason to render unknown file bytes directly in a terminal. Create a synthetic artifact whose first byte is Escape, followed by an apparent color sequence, text, and a NUL. Printf's \033 and \000 are octal escapes for those bytes. This file contains no real credential or executable payload.

Use an explicit one-record input and replace the preview with od -A n -t x1 -N 32 -- {}. The -A n option suppresses address offsets; -t x1 formats each byte as two hexadecimal digits; -N 32 limits the bytes read to at most thirty-two; and -- ends options. The od article distinguishes original bytes from their representation. Unlike the earlier sed preview, this command bounds the read as well as its displayed representation.

TERMINALBASH — DISPOSABLE LAB
printf '\033[31mTOKEN=demo\000end\n' > evidence.bin &&
printf '%s\n' ./evidence.bin |
  fzf --preview 'od -A n -t x1 -N 32 -- {}'
TERMINALEXPECTED PREVIEW BYTES
 1b 5b 33 31 6d 54 4f 4b 45 4e 3d 64 65 6d 6f 00
 65 6e 64 0a

Expected preview bytes, before Enter: Enter prints ./evidence.bin, not those preview bytes. The preview establishes only the inspected prefix of this chosen file; it does not authenticate evidence or prove later content is harmless. Keep original artifacts and record provenance separately. For a hostile directory, even the candidate names need a deliberate display policy; NUL framing solves pathname boundaries, not every terminal-display concern. This example uses one controlled, printable candidate name.

10

Add shell integration only at the shell boundary

The standalone selector works without shell integration. Once comfortable with it, Bash users can load fzf's generated integration into the current interactive shell. This changes key bindings and completion functions in that session. It does not edit a startup file; placing it there later is a separate configuration choice. Inspect the output of fzf --bash first if you want to review what will be loaded, and use a trusted installed executable.

The --bash flag prints Bash integration code. Command substitution captures that code; double quotes preserve it as one argument; eval asks the current shell to execute it. This is an intentional execution boundary for trusted program-generated integration, not a pattern for processing selected filenames or search results.

TERMINALBASH — DISPOSABLE LAB
eval "$(fzf --bash)"

Expected observation: on a supported interactive Bash session, Ctrl-R opens a command-history selector, Ctrl-T selects paths to insert at the command line, and Alt-C selects a directory and changes to it. These integrations have their own producer options and defaults; FZF_DEFAULT_COMMAND is not a universal override for every binding. A terminal or existing key map may intercept the keys. History can contain secrets; selecting it is not permission to log or share it. Ctrl-R retrieves a command for the command line rather than justifying its execution. Review the inserted text before Enter. Unlike the read-only file previews, Alt-C changes shell state. Keeping these effects explicit makes integration useful without pretending every fzf action is a passive filter.

11

Update the integration as well as the binary

Upstream's October 11, 2026, release notes and two project advisories document security fixes in 0.74.5. They describe affected versions as <= 0.74.4 and the patched version as 0.74.5. The tested 0.75.0 release retains those fixes. These are specific defects in companion integration code, separate from the intentional ability to run a preview or reload command.

GHSA-w6x2-f5m4-xw82 concerns bin/fzf-tmux. Unvalidated attached layout values could enter Bash arithmetic evaluation or inject tmux flags. Exploitation requires less-trusted data to reach those layout arguments and the victim to invoke the wrapper; normal trusted constant dimensions are not that data flow. The advisory describes this as local command injection as the invoking user, not an automatic consequence of selecting a malicious filename. The wrapper has been superseded by built-in tmux support, though existing integrations may still call it.

GHSA-7rj6-7pqx-v7rm concerns trigger-driven zsh completion, not the Bash setup above. A predictable FIFO, a named pipe, in a shared temporary directory could be pre-created by another local user, permitting overwrite or exposure of a completion stream under the advisory's conditions. The advisory notes that modern Linux protected-symlink and related protections constrain these attacks; do not drop that precondition when describing impact. Version 0.74.5 puts the FIFO inside a private temporary directory, and that repair remains in 0.75.0.

The November 7 release also fixes data races in the preview and search-result cache, plus quadratic action parsing in the optional --listen HTTP-control interface; upstream notes that a roughly 1 MB request could previously block that server for about thirty seconds. This article uses previews but not --listen. These are relevant upgrade reasons, not evidence that every preview command or listener deployment is safe.

Update companion scripts or their distribution package too, and reload the shell integration so an existing shell does not retain old functions. The project advisories include demonstrations; they do not establish exploitation in the wild, and none is asserted here. Upgrading fixes those documented defects. It does not make arbitrary preview commands, untrusted shell configuration, or unsafe downstream actions trustworthy.

12

Keep the selector's promise narrow

Build the producer first: which objects does it enumerate, what counts as a record, and how do you detect failure? Add fzf as a deliberate choice point. Decide whether its own matcher or an external backend owns the query, and keep previews cheap and appropriate for the data. Preserve NUL boundaries whenever arbitrary pathnames leave the interface.

Finally, make the consumer's effects explicit. Selecting a row is not the same as validating it, and accepting a chooser is not the same as authorizing deletion, restart, or execution. The useful abstraction is small: show the relevant candidates, let a person choose, and hand exactly those records to a known next step.

Back to latest issue
HELP SHAPE THE NEXT ISSUE

What belongs in your toolbox?

Choose a command you want to know better. We start with familiar tools and work toward the less obvious ones.

READER’S CHOICE

What should we cover next?

Vote for a future deep dive, or suggest a command we missed.

One command name, up to 32 characters. Suggestions are reviewed by a person. A new article starts a fresh poll.

Loading poll…