Fzf – A Quick Fuzzy File Search from Linux Terminal

Fzf is a tiny, blazing fast, general-purpose, and cross-platform command-line fuzzy finder, that helps you to search and open files quickly in Linux and Windows operating system. It is portable with no dependencies and has a flexible layout with support for Vim/Neovim plugin, key bindings, and fuzzy auto-completion.

The following GIF shows how it works.

Fzf - File Finder for Linux

To install Fzf, you need to git clone the fzf’s Github repository to any directory and run install script as shown on your Linux distribution.

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

After running the script, you will be prompted to enable fuzzy auto-completion, key bindings and update your shell configuration file. Answer y (for yes) to the questions as shown in the following screenshot.

Install Fzf in Linux
Install Fzf in Linux

On Fedora 26 and above, and Arch Linux, you can install it via a package manager as shown.

$ sudo dnf install fzf	#Fedora 26+
$ sudo pacman -S fzf	#Arch Linux 

Now that you have installed fzf, you can start using it. When you run fzf, it will open an interactive finder; reads the list of files from stdin, and writes the selected item to stdout.

Simply type the name of the file you are looking for in the prompt. When you find it, click enter and the relative path of the file will be printed to stdout.

$ fzf
Fzf Prompt
Fzf Prompt

Alternatively, you can save the relative path of the file your are searching, to a named file and view the content of the file using a utility such as cat command or bcat.

$ fzf >file
$ cat file
OR
$ bat file

You can also use it in conjunction with the find command, for example.

$ find ./bin/ -type f | fzf >file
$ cat file

How to Use Fuzzy Completion in Bash and Zsh

To trigger fuzzy completion for files and directories, add the ** characters as a trigger sequence.

$ cat **<Tab>
Auto Completion of Filenames
Auto Completion of Filenames

You can use this feature while working with environmental variables on the command-line.

$ unset **<Tab>
$ unalias **<Tab>
$ export **<Tab>
Auto Completing Env Variable in Linux
Auto Completing Env Variable in Linux

The same applies to the ssh and telnet commands, for auto-completing host names that are read from the /etc/hosts and ~/.ssh/config.

$ ssh **<Tab>
Auto Completing Hostnames
Auto Completing Hostnames

It also works with the kill command, but without the trigger sequence as shown.

$ kill -9 <Tab>
Auto Completion for Kill Command
Auto Completion for Kill Command

How to Enable fzf as Vim plugin

To enable fzf as a vim plugin, append the following line in your Vim configuration file.

set rtp+=~/.fzf

fzf is being actively developed and can be easily upgraded to latest version using following command.

$ cd ~/.fzf && git pull && ./install

To see the complete list of usage options, run man fzf or check out its Github Repository: https://github.com/junegunn/fzf.

Read Also: The Silver Searcher – A Code Searching Tool for Programmers

Fzf is a blazing fast and general-purpose fuzzy finder for quickly searching files in Linux. It has many use cases, for example, you can configure custom usage for your shell. If you have any questions or comments, reach us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply
  1. vim has its own :find command, and you can globstar a path (comma separated list) defined in your vimrc, or :cd /any_dir and run :find filename from there.

    vim will find and open the file almost instantly, and search 30 dirs deep by default (if memory serves me well), if the directory path is globstarred.

    (set path+=**,$HOME/Documents/**,$HOME/.config/**)
    

    You can define CDPATH (colon-separated list) in your .bashrc, and cd directly anywhere defined in $CDPATH.

    Both above examples utilized auto-completion.

    You can pipe find to grep as well. All just as fast, easy, good, or better, IMO.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.