Skip to main content

Basic Usage

fzf opens a full-screen TUI where you type a query to filter the input list and press Enter to output your selection. This lesson covers everything you need to use fzf from day one.

Invoking fzf

# Read from stdin (most common)
command | fzf

# Read from a file
fzf < filelist.txt

# No stdin — fzf runs find . by default
fzf # equivalent to: find . | fzf

The fzf TUI

┌─────────────────────────────────────────────────┐
│ > nginx ← your query│
│ 15 / 1024 ← match count│
│ ▶ /etc/nginx/nginx.conf │
│ /etc/nginx/sites-available/default │
│ /var/log/nginx/error.log │
│ /var/log/nginx/access.log │
└─────────────────────────────────────────────────┘
ElementMeaning
> promptYour query input
15 / 102415 matches out of 1024 total items
pointerCurrently highlighted item

Default Key Bindings

KeyAction
/ Ctrl+k / Ctrl+pMove up
/ Ctrl+j / Ctrl+nMove down
Page UpScroll up one page
Page DownScroll down one page
HomeGo to first item
EndGo to last item
Ctrl+uClear query
Ctrl+aSelect all (with -m)
Ctrl+dDeselect all (with -m)

Confirmation

KeyAction
EnterAccept selection
Esc / Ctrl+cCancel (exit 130)
Ctrl+qCancel

Text Editing

KeyAction
Ctrl+wDelete previous word
Ctrl+uClear the query
← →Move cursor in query
Ctrl+aMove to start of query
Ctrl+eMove to end of query

Essential Flags

--multi / -m — Select Multiple Items

ls | fzf -m
# Tab to mark items, Shift+Tab to unmark, Enter to output all marked
KeyAction
TabToggle selection
Shift+TabToggle selection (backward)
Ctrl+aSelect all
Ctrl+dDeselect all

Multi-select output: one selected item per line.

--query / -q — Pre-fill the Query

ls /etc | fzf --query "nginx"
# Opens fzf with "nginx" already typed

--select-1 / -1 — Auto-select If Only One Match

ls | fzf --query "nginx.conf" --select-1
# If exactly one result matches, skip TUI and output it directly

--exit-0 / -0 — Exit Immediately If No Match

ls | fzf --query "doesnotexist" --exit-0
# Exits with code 1 if no matches — useful in scripts

--filter / -f — Non-interactive (Batch) Mode

ls | fzf --filter "conf"
# Outputs all matches without TUI (like grep but fuzzy)
# Useful for scripting without user interaction

--height — Use Partial Screen Height

ls | fzf --height 40%
# fzf uses 40% of screen height instead of full screen

--reverse — Input at Top

ls | fzf --reverse
# Query prompt and results start from top of screen

--prompt — Custom Prompt Text

ls | fzf --prompt "  Open file: "

--header — Informational Header

ls | fzf --header "Select a file to edit (Enter to open)"

Reading the Exit Code

fzf returns different exit codes:

Exit codeMeaning
0Item selected
1No match (with --exit-0) or no selection
130Interrupted with Ctrl+c or Esc
# In scripts:
selected=$(ls | fzf)
if [ $? -eq 0 ]; then
echo "You selected: $selected"
elif [ $? -eq 130 ]; then
echo "Cancelled"
fi

The --print0 Flag — Handle Filenames with Spaces

# Safe for filenames containing spaces or special characters
find . -name "*.txt" -print0 | fzf --read0 --print0 | xargs -0 cat

Practical First Commands

# Pick a file to edit
nvim "$(find . -type f | fzf)"

# Pick multiple files to delete (with confirmation)
find . -name "*.tmp" | fzf -m | xargs -I{} rm -v {}

# Pick a running process to kill
kill $(ps aux | fzf | awk '{print $2}')

# Pick a line from a log file to examine
grep -n "" /var/log/syslog | fzf | cut -d: -f1

# Select from history and run
eval $(history | awk '{$1=""; print $0}' | fzf)

What's Next