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 AlsoThe Silver Searcher – A Code Searching Tool for Programmers

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com