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 not match pyc and match exactly travis
$ fzf [[-q|--query]] "\!pyc 'travis'"
copy

SYNOPSIS

fzf [options]
command | fzf [options]
fzf [options] < input_file

PARAMETERS

--query=
    Initial query string.

--filter=
    Filter mode. Do not start interactive finder. Output matching lines to stdout and exit.

--multi
    Enable multi-select mode. Press TAB or Shift-TAB to mark/unmark. Enter confirms selections.

--no-sort
    Do not sort the result. Useful when preserving the original order is desired.

--reverse
    Display lines in reverse order (bottom-up).

--preview=
    Execute `command` for the currently highlighted item and display its output in the preview window. Use `{}` as a placeholder for the item.

--preview-window=:[:]
    Customize the preview window layout. E.g., `right:50%`.

--height=%
    Display `fzf` as a partial-height window, rather than fullscreen.

--layout=reverse
    Display the search prompt at the bottom of the screen.

--prompt=
    Input prompt string. (Default: `> `).

--print0
    Print selected item(s) separated by null characters. Useful for piping to `xargs -0`.

--ansi
    Enable processing of ANSI color codes in the input.

--expect=
    Comma-separated list of keys to exit `fzf` and print the name of the key pressed.

--bind=:[,:...]
    Bind a key or key combination to an action. E.g., `ctrl-a:select-all`.

--history=
    Load and save history from the specified file.

--select-1
    Automatically select the only match if there is exactly one.

--exit-0
    Exit with 0 if no match found, and nothing is selected.

DESCRIPTION

`fzf` is a general-purpose command-line fuzzy finder written in Go. It provides an interactive interface to efficiently filter and select items from any list, typically presented via standard input. Its strength lies in its speed, flexibility, and intuitive fuzzy-matching algorithm, which allows users to quickly narrow down choices even with partial or imprecise input. `fzf` is highly customizable and designed to be integrated seamlessly with other command-line tools and shell environments. Common use cases include finding files, searching command history, filtering process lists, and navigating directories. It processes lines from standard input and outputs the selected line(s) to standard output, making it an excellent component in powerful shell pipelines.

CAVEATS

`fzf` relies on external commands for its preview functionality, which must be installed separately. While highly optimized, performance can still be a factor with extremely large input sets (millions of lines). Integrating `fzf` with complex shell functions or aliases often requires careful attention to quoting and shell expansion rules.

SHELL INTEGRATION

`fzf` provides excellent shell integration, significantly enhancing common shell tasks. For instance, `CTRL-T` (for Bash/Zsh) often invokes `fzf` to select files from the current directory and its subdirectories, `ALT-C` allows for quick directory switching, and `CTRL-R` provides an interactive, fuzzy search through your shell history. These integrations leverage `fzf`'s core filtering capabilities to provide a much more efficient and intuitive user experience.

PIPING AND CHAINING

`fzf` is designed to work as a filter in shell pipelines. You can pipe the output of any command into `fzf` to interactively select items, and then pipe `fzf`'s output to another command. This makes it incredibly versatile for creating custom workflows, such as `ls -l | fzf --multi | xargs rm` to interactively select and delete files.

HISTORY

`fzf` was created by Junegunn Choi and first released around 2014-2015. Developed in Go, it quickly gained popularity for its exceptional speed and portability across various operating systems. Its simple yet powerful fuzzy-matching algorithm, combined with a highly customizable interface, made it a favorite among command-line users for interactive filtering tasks. The project has seen continuous development and has become a de facto standard tool for enhancing shell productivity, particularly through its widely adopted shell key bindings (e.g., `CTRL-T`, `ALT-C`, `CTRL-R`).

SEE ALSO

grep(1), find(1), xargs(1), sed(1), awk(1), ripgrep(1), fd(1)

Copied to clipboard