If you spend more than two hours a day in the terminal, you know the frustration of trying to find a specific file in a deeply nested directory or searching through a massive command history. For years, I relied on a combination of find, grep, and a lot of mindless tabbing. Then I discovered fzf.

In this fzf command line tutorial, I’m going to show you how to integrate a general-purpose fuzzy finder into your workflow. Unlike standard search tools, fzf doesn’t require you to remember the exact name of a file; it finds the closest match based on what you type in real-time. It’s one of those tools that, once installed, makes every other modern unix command feel incomplete.

Prerequisites

Before we dive in, ensure you have the following installed on your system:

Step 1: Installing fzf

Installing fzf is straightforward. Depending on your OS, I recommend using the official git installation method because it includes the useful shell extensions (keybindings and auto-completion).

# Clone the repository into your home directory
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf

# Run the install script
~/.fzf/install

During the installation, the script will ask if you want to enable fuzzy completion and keybindings. Say yes to all of them. This is where the real magic happens.

Step 2: Mastering the Basics

Once installed, running fzf by itself will list all files in the current directory and let you filter them. But the real power comes from using it as a filter for other commands.

Filtering File Lists

Instead of scrolling through ls, pipe the output into fzf:

# Find a file and print its name
ls | fzf

Integrating with the Editor

In my daily setup, I rarely use vim filename. Instead, I use fzf to select the file first. Here is a simple alias I added to my .zshrc:

# Open a selected file in Vim
vim $(fzf)

As shown in the image below, this eliminates the need to type out long paths manually, allowing you to jump straight into the code.

Terminal output showing fzf filtering a list of files with a selected result highlighted in blue
Terminal output showing fzf filtering a list of files with a selected result highlighted in blue

Step 3: Using Built-in Keybindings

If you enabled the shell extensions during installation, you now have three game-changing shortcuts:

Step 4: Advanced Integration & Automation

To truly optimize your productivity, you can combine fzf with other tools. For example, if you are using the gh cli workflow automation patterns, you can use fzf to pick which PR to checkout.

# Pick a PR number using fzf and checkout the branch
gh pr list | fzf | awk '{print $1}' | xargs -I {} gh pr checkout {}

Customizing the Preview Window

One of my favorite features is the preview window. By using the --preview flag, you can see the content of a file before you select it. I use bat (a cat clone with syntax highlighting) for this:

# fzf with a syntax-highlighted preview
fzf --preview 'bat --style=numbers --color=always --line-range :500 {}'

Pro Tips for Power Users

Troubleshooting Common Issues

Issue: Keybindings aren’t working.
Ensure you have sourced the fzf shell script in your configuration file. For Zsh, check if [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh is present in your .zshrc.

Issue: fzf is slow in huge directories.
If you are searching through a massive monorepo, the default find command can be slow. Install fd-find and add this to your shell config: export FZF_DEFAULT_COMMAND='fd --type f'.

What’s Next?

Now that you’ve mastered the basics of this fzf command line tutorial, I recommend exploring zoxide for smarter directory jumping or looking into my guide on modern unix commands to replace other legacy tools in your stack.