Weekly Command: Fuzzy finding everything with fzf

April 26th, 2018 weekly-command xnix

The Basics

fzf [--options]

fzf is an interactive fuzzy finder, it reads a list of items from STDIN, and writes the selected item to STDOUT.

If no input is provided via STDIN, fzf by default will use the find command to fetch the list of files excluding hidden ones.

fzf fits very well into to the *nix philosophy, which gives it a lot of flexibility, including a lot of built-in goodness for bash and zsh shells (head to the examples for more).

The program is portable, has no dependencies and can be installed easily following the instructions in the README of the project.


Without further introduction, here are some examples of fzf in action.



As stated earlier, fzf can be invoked on its own, and it will provide fuzzy completion for the items found in the current directory and subdirectories.



$ fzf --preview="head -$LINES {}"

In addition, you can provide a --preview flag with a command to execute when a file is selected. The command string accepts placeholders to be replaced by fzf during file selection:

Fuzzy completion for commands


# Files under current directory
$ cat **<TAB>
# Processes
$ kill -9 <TAB>
# Host names
$ ssh **<TAB>
# Environment variables / Aliases
$ export **<TAB>

A great feature which comes bundled-in for bash and zsh is fuzzy completion for different commands, in most cases just typing ** and pressing (TAB) will give you the fuzzy completion interface to feed the command with the selected items.

On bash, fuzzy completion is enabled only for a predefined set of commands via the complete built in, but you can enable it for other commands with:

complete -F _fzf_path_completion -o default -o bashdefault <COMMAND_NAME>

Searching history


Also by default in bash and zsh, there’s built-in support for the reverse incremental history search.

Further configuration

You can provide additional configuration options via environment variables:



I try to post once a week interesting stuff about programming, *nix, and the web. If you’d like to be notified when a new post goes out, you can subscribe with the form below.

Roberto Dip