fzf: Fuzzy-Find Everything and Never Scroll Your Shell History Again

Ever pressed the up arrow 47 times looking for that one docker command from last Tuesday? fzf turns your history, your files and your folders into a search box that forgives your typos.

Tux Harlow

3 min read

Have you ever pressed the up arrow 47 times looking for that one docker run command from last Tuesday? The one with all the flags? You pass it, panic, press down, overshoot, and end up running ls for the fourth time out of pure despair?

Friend. Put the arrow key down. Meet fzf.

fzf is a fuzzy finder. You give it a list of anything (files, commands, git branches, your hopes and dreams) and it gives you a search box that forgives typos. Type dkrrun and it finds docker run. It's like autocomplete that went to therapy and learned to be supportive.

Install it

Bash
sudo apt install fzf     # Debian, Ubuntu
sudo dnf install fzf     # Fedora

Now the important bit, the shell integration. That's where the magic keys come from. On a recent fzf (0.48 and later), add one line to your shell's config file:

Bash
# ~/.bashrc
eval "$(fzf --bash)"
Zsh
# ~/.zshrc
source <(fzf --zsh)

Is your distro's fzf older? The same bindings ship as a script, usually under /usr/share/doc/fzf/examples/ on Debian and Ubuntu, and you source that instead. Open a new terminal and let's play.

Ctrl-R: your history, but searchable

Press Ctrl-R and your entire shell history appears in a list, with a search box at the bottom. Type a few letters of anything you remember: rsync bak, kubectl logs, that ssh thing. (Okay, maybe not that last one.) Arrow up or down to pick, press Enter, and the command lands on your prompt, ready to edit or run.

This one key is worth the whole install. Your up-arrow can finally retire.

Ctrl-T: paste a file path

Typing vim and can't remember where that config file lives? Press Ctrl-T, fuzzy-search every file under the current folder, hit Enter, and the path gets pasted right where your cursor is.

vim <Ctrl-T>  →  type "ngx conf"  →  vim ./deploy/nginx/site.conf

Press Tab on several files to pick more than one.

Alt-C: teleport into a folder

Alt-C lists every directory under you. Pick one and you're cd'd straight into it. It's basically teleportation, minus the risk of arriving with your molecules rearranged.

The ** trick

With the integration loaded, two stars and Tab open fzf right in the middle of a command:

Bash
cd **<Tab>
vim **<Tab>
ssh **<Tab>       # hosts from your ssh config and known_hosts
kill -9 **<Tab>   # pick a process from a list

That last one is great. No more ps aux | grep and copying the PID by hand like it's 1998.

Previews, because we're fancy

fzf can show a preview of whatever is highlighted:

Bash
fzf --preview 'head -50 {}'

{} is the highlighted line. If you have bat installed (it's in a review coming up soon, wink), swap in bat --color=always {} for syntax-highlighted previews and feel like a movie hacker.

Pipe anything into it

Here's the secret: fzf doesn't care what the list is. Anything that prints lines can feed it:

Bash
git branch | fzf | xargs git checkout

That's a fuzzy branch switcher in one line. Your Git branches are called fix-thing-2-final-REAL, aren't they? Now it doesn't matter.

Bash
vim "$(fzf)"

That opens whatever you pick.

The verdict

fzf is one of those tools where, a week in, you try to use someone else's terminal, press Ctrl-R, and feel genuinely betrayed. Install it, add the one line, and use Ctrl-R for a day. That's all it takes.

Your up-arrow key will thank you. It was getting tired.