LinuxCommandLibrary

fzf

Fuzzy find files and directories interactively

TLDR

Start fzf on all files in the specified directory

$ find [path/to/directory] -type f | fzf
copy

Start fzf for running processes
$ ps aux | fzf
copy

Select multiple files with and write to a file
$ find [path/to/directory] -type f | fzf [[-m|--multi]] > [path/to/file]
copy

Start fzf with a specified query
$ fzf [[-q|--query]] "[query]"
copy

Start fzf on entries that start with core and end with either go, rb, or py
$ fzf [[-q|--query]] "^core go$ | rb$ | py$"
copy

Start fzf on entries that do not match pyc and contain travis
$ fzf [[-q|--query]] '!pyc travis'
copy

SYNOPSIS

fzf [options] [--] [INPUT]

PARAMETERS

--height
    Specify height of fzf window (e.g., 40%, 20, '80%' or 'cover')

--layout
    Layout of fzf window: 'default', 'reverse', 'reverse-list'

--border
    Border style: 'sharp', 'rounded', 'double', 'horizontal', 'vertical', 'single', 'none'

--preview ''
    Command to generate preview content (e.g., --preview 'bat --color=always {}')

--preview-window
    Position and size of preview window (e.g., 'up:50%:wrap')

--multi
    Enable multi-select with Tab

--bind
    Custom key bindings (e.g., --bind 'ctrl-j:accept')

--exact
    Enable exact fuzzy matching

--no-sort
    Disable sorting of results

--tac
    Reverse-sort input lines (latest first)

--ansi
    Enable processing of ANSI color codes

--filter
    Filter mode: select matching lines without interactive interface

--expect
    Keys that invoke callback script on key-press

--print-query
    Print query as first line of output

--no-mouse
    Disable mouse support

-q --query
    Start search with given query string

-m --multi
    Enable multi-selection

--version
    Display version information

--help
    Display comprehensive help

DESCRIPTION

fzf is a versatile command-line fuzzy finder designed for rapid interactive searching and selection from lists. It excels at filtering large datasets in real-time using fuzzy matching algorithms, making it ideal for tasks like navigating directories, searching command history, killing processes, or selecting from git branches.

Pipe input into fzf via stdin, and it displays a scrollable, searchable interface where typing narrows results instantly with highlighted matches. Default keybindings include Ctrl-r for reverse search, Ctrl-j/k for navigation, and Enter to select. Multi-selection is supported with Tab.

Key features include customizable layouts (e.g., full-screen, popup), preview windows for context (using --preview), extensive key bindings via --bind, and shell integrations for zsh, bash, fish, vim, and tmux. Written in pure Go, it's portable, fast (handles millions of lines), and supports ANSI colors, Unicode, and mouse input.

Usage examples: fd --type f | fzf for fuzzy file selection, history | fzf for command history, or ps aux | fzf --multi | awk '{print $2}' | xargs kill. Its extensibility via scripts and bindings makes it a shell powerhouse.

CAVEATS

Not installed by default on most distros; requires manual installation (e.g., via package managers or GitHub releases). Relies on terminal emulator support for advanced features like true color and mouse. Preview commands must be efficient to avoid lag. Fuzzy matching may not suit all locales without tweaks.

DEFAULT KEY BINDINGS

Ctrl-r: Jump to previous line
Ctrl-j/k: Move down/up
Alt-j/k: Move down/up half page
Ctrl-f/b: Page forward/backward
Tab: Toggle selection (multi)
Enter: Select
Esc: Cancel

SHELL INTEGRATION

Source fzf.sh for enhanced completions (e.g., Ctrl-t for files, Ctrl-r for history, Alt-c for cd). Install via git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install.

EXAMPLES

vim $(fzf): Edit selected file
kill -9 $(ps aux | fzf -m | awk '{print $2}'): Kill processes
git log --oneline | fzf | cut -d' ' -f1 | xargs git checkout: Fuzzy checkout

HISTORY

Developed by Junegunn Choi starting in 2015 as a faster alternative to fuzzy finders like percol. First GitHub release v0.10.0 in March 2015; now at v0.52.1 (2024). Gained massive popularity via shell integrations, surpassing 60k stars on GitHub. Evolved with tmux, vim/neovim plugins, and advanced features like ripgrep integration.

SEE ALSO

find(1), grep(1), rg(1), fd(1), bat(1), skim(1)

Copied to clipboard