Fzf: Quick Search via Fuzzy Finder on Linux (Install + Use)

Linux TLDR
Last Updated:
Reading time: 4 minutes

โ€œfzfโ€ (or fuzzy finder) is a small, blazingly fast, and cross-platform command-line utility that allows you to perform interactive or dynamic searches via an interactive interface for effortless navigation and selection from matching options.

Itโ€™s very flexible, and most often you will use it with pairs of two commands, whether theyโ€™re related to files, command history, processes, hostnames, git commits, etc., piped together.

To be honest, when I initially discovered this tool, I first read the official documentation, which was a bit overwhelming. Later, I found the following official Fzf explanation videos, which I watched, and then I understood why and how you can use it to improve your command-line productivity.

In this article, I explain its installation steps on most Linux distributions and a few command-line usages that I personally use.

Tutorial Details

Descriptionfzf: Fuzzy Finder
Difficulty LevelModerate
Root or Sudo PrivilegesNo
OS CompatibilityLinux, Windows, and macOS
Internet RequiredYes (for installation)

How to Install Fzf on Linux

The โ€œfzfโ€ can be easily installed on Linux in multiple ways; on macOS, you can refer to the brew section in this article, and users on a Windows system can install it via Chocolatey, Scoop, Winget, and MSYS2.

Since this article is primarily aimed at Linux users, if youโ€™re running a Linux system, you can install โ€œfzfโ€ in multiple ways, each of which is mentioned below for you to choose based on your preferences.

Installing Fzf Using Package Manager

If you are using one of the following Linux distributions where โ€œfzfโ€ is readily available in the repository, you can use your default package manager to install it.

In the future, a new Linux distribution may be added; for the most up-to-date list, refer to the link.
  • Alpine Linux Edge
  • Arch
  • Gentoo
  • openSUSE Tumbleweed
  • Termux
  • Void Linux

The following are commands to install โ€œfzfโ€ using the default package manager on the supported distribution.

#On Alpine Linux
$ sudo apk add fzf

#On Debian and Ubuntu
$ sudo apt install fzf

#On RedHat and Fedora
$ sudo dnf install fzf

#On Nix
$ nix-env -iA nixpkgs.fzf

#On Arch and Manjaro
$ sudo pacman -S fzf

#On Gentoo
$ emerge --ask app-shells/fzf

#On OpenSUSE
$ sudo zypper i fzf

Installing Fzf Using Brew

If Brew is installed on your Linux system, or if you are running macOS, simply execute the following command to install it.

$ brew install fzf

Then run the following command to install useful key bindings and fuzzy completion:

$ $(brew --prefix)/opt/fzf/install

Installing Fzf Using Git

Lastly, you can install it by cloning the project directory and then executing the install script.

$ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
$ ~/.fzf/install

How to Use Fzf

Once installed, when you start using it by issuing the โ€œfzfโ€ command, it will open an interactive finder in your current path, which will recursively start searching for all the files under the current directory tree from โ€œstdinโ€ and write the selected item to โ€œstdoutโ€œ.

BTS: It uses the find command to pipe a list of files to Fzf (ref: โ€œfind * -type f | fzfโ€œ).
$ fzf


fzf command output

There is also a way to start โ€œfzfโ€ right away with other commands using the โ€œCtrl+Tโ€ shortcut key, adding โ€œ**โ€ as a parameter, then pressing the โ€œTabโ€ key, or by adding โ€œ$(fzf)โ€ to the command as an argument.

The correct key bindings for Bash, Zsh, and Fish are โ€œCTRL+Tโ€œ, โ€œCTRL+Rโ€œ, and โ€œALT+Cโ€œ, respectively.

Feeling overwhelmed, right? Let me explain with an example. So, if youโ€™re planning to read a file using a cat command or want to open it with editors like Vim or Nano.

Then, traditionally, you would type the command and specify the path to your file (typing the path manually). However, by using โ€œfzfโ€ with your command, you can directly open an interactive session where you can quickly locate your file and open it with the specified command without typing the complete path manually.

Hereโ€™s an example demonstrating how โ€œfzfโ€ can assist you in easily locating your files.

#Quickly locating file to read using Fzf
$ cat <press Ctrl+TAB>
$ cat **<press TAB>
$ cat $(fzf)


#Quickly locating file to edit using Fzf
$ vim <press Ctrl+TAB>
$ vim **<press TAB>
$ vim $(fzf)

Now, these were the basic usages of โ€œfzfโ€œ, but its real power lies in using it with other commands via piping, allowing you to interactively search whatever you pipe to it via the โ€œ|โ€ operator. For example, you can use the following command to select from a list of running processes and then choose the one you wish to close.

$ ps aux | fzf | awk '{print $2}' | xargs kill


closing file using fzf

Here, the โ€œps auxโ€ command will list all the running processes, then pipe the results to โ€œfzfโ€ for you to select them. Once you make a selection, the awk command selects the process ID from the second column, and โ€œxargsโ€ submits the result back to the โ€œkillโ€ command.

Until now, when the โ€œfzfโ€ interactive session launched, it listed all the files from the current directory. However, if you are only looking for specific files, such as text or images, then going through all the results seems time-consuming.

To save time, specify the specific file type via their extension to โ€œfzfโ€ with the โ€œ--queryโ€ option to only show them in the interactive session.

#To only list a file named "README".
$ fzf --query "README"

#To only list a text file.
$ fzf --query ".txt"

#To only list an image file.
$ fzf --query ".jpg"

#To only list a video file.
$ fzf --query ".mp4"

The following is an output of only listing text files in the โ€œfzfโ€ interactive search.

search only text file in fzf

Iโ€™ll leave it, as further exploration is too easy to do by oneself.

How to Remove Fzf from Linux

If you want to remove โ€œfzfโ€ from your Linux system, simply follow the method you followed during installation. For example, if you have installed it via Package Manager, then run the respective command.

#On Alpine Linux
$ sudo apk del fzf

#On Debian and Ubuntu
$ sudo apt remove fzf

#On RedHat and Fedora
$ sudo dnf remove fzf

#On Nix
$ nix-env -e nixpkgs.fzf

#On Arch and Manjaro
$ sudo pacman -R fzf

#On Gentoo
$ emerge --deselect app-shells/fzf

#On OpenSUSE
$ sudo zypper rm fzf

If you have installed it via Brew, then run:

$ brew uninstall fzf

Lastly, installation via script can be removed by running:

$ ~/.fzf/uninstall

Final Word

Fzf is super fast and can be used in many cases. For example, you can create a different alias for โ€œfzfโ€ with different options and instantly use them when editing a file, closing processes, or stopping services; the scope is very wide.

If you have any questions or queries related to the topic, then do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.