Quick Start with fzf (Interactive Command Line Fuzzy Finder)

I mentioned fzf many times in my Linux Uprising article, but I never really wrote about it. fzf has been part of my workflow for a long time and is an excellent tool you should know about.

I know that many of you are already using fzf, but for those who do not use fzf, this article is for you. This is just a brief introduction to fzf without involving too many details. fzf Project page with Wiki Provides extensive information about fzf, its usage, and many examples, so please check these for more information.

fzf It is a fast, interactive command line fuzzy finder written in Go language. The tool is available for Linux, macOS, *BSD and Windows.

You can use Shell extensions (including fuzzy auto-completion of Bash and Zsh, as well as such CTRL-T, CTRL-R with ALT-C (For Bash, Zsh and Fish), and as a Vim/Novim plugin. There is also a Tmux script to start fzf in the Tmux pane.

The functions of these fzf command line key bindings are as follows:

  • CTRL-R: Search your command history.press Enter Paste the command selected from the history to the command line.Sort correlation with chronological order by switching CTRL-R Again (by default, sorting is done based on relevance)
  • CTRL-T: Display the list of files and folders in the current directory (and subdirectories).press Enter Paste the selected file/folder path to the command line
  • ALT-C: Display the list of subdirectories in the current directory.press Enter To cd Enter the selected directory

By default, the search syntax allows you to type multiple search terms separated by spaces (fzf starts in extended search mode). If you want to find an exact match, put single quotes before the search term (for example, 'search-term).More information on fzf search syntax Here.

The interactive fzf finder uses the following key bindings by default: / (or CTRL-J / CTRL-K or CTRL-N / CTRL-P) Move the cursor up and down, Enter Key to select an item, then CTRL-C (or CTRL-G / ESC) drop out.When using -m Command line parameters, in this case you can use TAB with Shift-TAB.

fzf also has mouse support, so you can click, scroll, double-click items, etc.For multiple selection mode, you can use Shift-click with Shift-scroll.

Other functions of fzf also include the function of displaying the preview pane (--preview=COMMAND), set its height (e.g. --height 50%), add a border (--border), use custom key bindings, use different layouts (such as reverse layout), enable processing of ANSI color codes, and so on.

Fuzzy search of your shell history (CTRL-R):

fzf ctrl-r animated gif example

Fuzzy completion of files and directories (triggered by ending the command with the trigger sequence, by default it is **, then press TAB):

cd **<TAB>

fzf cd ** <TAB>Animated gif example “border=”0″ data-original-height=”500″ data-original-width=”820″ src=”https://1.bp.blogspot.com/-eq-WxerSYwM/YEoXipORw3I/AAAAAAAAFV8%20/Sq54v3HQqtM5d06oFJSKiSFhtR7gWwXJgCLcBGAsYHQ/s16000/fzf-cd-tab.gif” title=”fzf cd ** <TAB>Animated gif example”></a></p><p>Similarly, fzf can also automatically complete the hostname (for example <code>ssh **<TAB></code>), as well as environment variables and aliases (e.g. <code>export **<TAB></code>).It can also automatically complete the process ID, in this case, there is no trigger sequence, for example <code>kill -9 <TAB></code>.</p><div class=

In the current directory (and subdirectories) and when selecting files (by pressing Enter Key), open the file through the default command line editor:

editor $(find * -type f | fzf)

Fzf open file gif animation example

Use it in conjunction with other commands to create a cool interactive console UI with fuzzy search and preview panes. For example, the following command (by) Use fzf and apt to list all available packages, allowing you to press Enter key.Here, fzf and --preview Options to display the preview pane (in this case, it shows the selected DEB package details):

apt-cache search '' | sort | cut --delimiter ' ' --fields 1 | fzf --multi --cycle --reverse --preview 'apt-cache show {1}' | xargs -r sudo apt install -y

fzf apt installation, with detailed information gif animation example

For the screenshot at the top of this article, I am using the following command (it requires bat, One cat A clone written in Rust, which includes syntax highlighting, etc.):

fzf --preview 'bat --style=numbers --color=always --line-range :500 {}'

For more advanced examples, check out fzf Wiki.

I also wrote some command line tools/scripts using fzf fuzzy finder on Linux Uprising:

  • forgit: Interactive Git command with preview function supported by fzf Fuzzy Finder
  • ytfzf-Search (with thumbnails) and play YouTube videos on the terminal
  • z.lua-a faster way to change directories (cd command that you will learn when you use it)

Install FZF Fuzzy Finder

fzf is available for Linux (including various ARM versions, so it can run on Raspberry Pi), macOS, *BSD and Windows.

On Linux, you can download from Repository It runs on Debian9+, Ubuntu 19.10+, Fedora, Arch Linux, openSUSE, etc.

However, I personally prefer to use its installation script for installation (it will automatically download the binary file for your system without having to build it from the source code). That’s because it sets everything up for you, the only thing needed is to purchase the shell configuration file. It is also easy to update to newer fzf versions (they are released frequently).

To install fzf using its installation script, make sure you have git Install and then use:

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


The installation script will ask you some questions about which features are enabled. You probably want to answer yes (y) To everyone.

That’s it. Now, all you have to do is restart the shell or reload the configuration file:

  • Heavy hit:
source ~/.bashrc

  • Zsh:
source ~/.zshrc

  • fish:

Using this installation method, if you want to update it later (complete files and binary files), use:

cd ~/.fzf

git pull


It’s also easier to uninstall it (this undoes the right ~/.bashrc or ~/.zshrcAnd remove the Fish key binding from it ~/.config; It will not delete ~/.fzf table of Contents):

cd ~/.fzf



Related Posts