How to Install and Use fzf on Linux: The Complete Guide to Fuzzy Finding in the Terminal
If you spend significant time in the Linux terminal, you already know that finding files, recalling commands, and navigating directories can slow you down. fzf (Fuzzy Finder) is a blazing-fast, interactive command-line tool that eliminates that friction entirely. Whether you're filtering thousands of files, searching command history, or switching Git branches, fzf transforms tedious terminal tasks into fluid, near-instant operations.
In this comprehensive guide, you'll learn how to install fzf on Linux, master its core features, integrate it with popular tools, and customize it to fit your exact workflow.
> Running your own Linux environment? A powerful development setup starts with the right infrastructure. AlexHost's VPS Hosting gives you full root access, high-performance SSD storage, and complete freedom to configure your server β the ideal foundation for building a productive Linux terminal workflow.
What Is fzf?
fzf is a general-purpose, command-line fuzzy finder written in Go. It reads a list of items from standard input and presents them in a real-time, interactive filtering interface. As you type, fzf narrows down results using a fuzzy-matching algorithm β meaning you don't need to type exact strings to find what you're looking for.
Key capabilities of fzf include:
- File and directory search across large directory trees
- Command history navigation with instant recall
- Git branch and commit browsing
- Process management and interactive killing
- SSH host selection from your config file
- Integration with virtually any command that produces line-based output
fzf is lightweight, dependency-free after installation, and works seamlessly with Bash, Zsh, and Fish shells.
Installing fzf on Linux
There are two primary installation methods: cloning the official Git repository or using your distribution's package manager. Both are straightforward.
Method 1: Install via Git (Recommended for Latest Version)
Installing from the GitHub repository ensures you always get the most up-to-date version.
Step 1 β Clone the repository:
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzfStep 2 β Run the install script:
cd ~/.fzf
./installDuring installation, you'll be prompted with three configuration questions:
- Enable key bindings? (Recommended: Yes) β Adds
Ctrl+T,Ctrl+R, andAlt+Cshortcuts - Enable fuzzy auto-completion? (Recommended: Yes) β Enables tab-completion integration
- Update shell configuration files? (Recommended: Yes) β Automatically sources fzf in
.bashrc/.zshrc
After installation, reload your shell:
source ~/.bashrc # For Bash users
source ~/.zshrc # For Zsh usersMethod 2: Install via Package Manager
Package manager installation is faster and integrates with your system's update mechanism, though it may provide a slightly older version.
Ubuntu / Debian:
sudo apt update && sudo apt install fzfFedora:
sudo dnf install fzfArch Linux / Manjaro:
sudo pacman -S fzfmacOS (Homebrew):
brew install fzf
$(brew --prefix)/opt/fzf/installVerify your installation:
fzf --versionBasic Usage of fzf
Once installed, fzf is immediately usable. Here are the essential commands to build your foundation.
1. Interactive File Search
Launch fzf in your current directory to interactively search files:
fzfAn interactive prompt appears. Begin typing any part of a filename β fzf filters results in real time. Use the arrow keys to navigate, and press Enter to select.
Useful navigation shortcuts:
| Key | Action |
|---|---|
β / β | Navigate results |
Enter | Confirm selection |
Tab | Mark multiple items |
Ctrl+C / Esc | Cancel |
2. Search Command History
One of fzf's most popular use cases is interactive command history search:
history | fzfIf you enabled key bindings during installation, you can press Ctrl+R at any time in your terminal to trigger this instantly β far more powerful than the default reverse-search.
3. Combine fzf with find
Search recursively through your filesystem and pipe results into fzf:
find . -type f | fzfTo search only for directories:
find . -type d | fzf4. Navigate to a Directory with Alt+C
If you enabled key bindings, pressing Alt+C opens an interactive directory navigator. Select a directory and fzf automatically runs cd to navigate there.
5. Search Git Branches
Quickly find and reference Git branches in large repositories:
git branch | fzfTo check out a branch interactively:
git checkout $(git branch | fzf)Integrating fzf with Other Commands
fzf's real power emerges when you combine it with other tools using command substitution ($(fzf)).
1. Open a File Directly in vim or nano
vim $(fzf)nano $(fzf)Type part of a filename, select it, and the editor opens immediately β no need to type the full path.
2. Copy a File Path to the Clipboard
fzf | xclip -selection clipboardOn systems using xsel:
fzf | xsel --clipboard --input3. Interactive SSH Host Selection
If you manage multiple servers, this integration is a game-changer:
ssh $(grep -i "^Host " ~/.ssh/config | awk '{print $2}' | fzf)This parses your SSH config file and lets you interactively select a host before connecting β no more memorizing hostnames or IP addresses.
> Managing multiple remote servers? AlexHost's Dedicated Servers provide enterprise-grade hardware with full administrative control, making them perfect for teams that rely on SSH-heavy workflows.
4. Kill a Process Interactively
kill -9 $(ps aux | fzf | awk '{print $2}')List all running processes, fuzzy-search for the one you want, and kill it β all without needing to know the PID in advance.
5. Preview File Contents While Searching
fzf supports a --preview flag that displays file contents alongside your search results:
fzf --preview 'cat {}'For syntax-highlighted previews (requires bat):
fzf --preview 'bat --color=always {}'Customizing fzf
fzf is extensively configurable through environment variables and shell configuration files.
1. Set Default Options with FZF_DEFAULT_OPTS
Add this to your ~/.bashrc or ~/.zshrc to apply options globally:
export FZF_DEFAULT_OPTS="--height 40% --reverse --inline-info --border"Common options explained:
| Option | Description |
|---|---|
--height 40% | Display fzf in the lower 40% of the terminal |
--reverse | Show results top-to-bottom (input at top) |
--inline-info | Display match count inline |
--border | Draw a border around the fzf window |
--multi | Enable multi-select with Tab |
2. Customize Colors
Match fzf's color scheme to your terminal theme:
export FZF_DEFAULT_OPTS="--color=bg+:#3c3836,bg:#282828,fg:#ebdbb2,fg+:#ebdbb2,hl:#fabd2f,hl+:#fabd2f,info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,border:#665c54"This example uses the popular Gruvbox color scheme. Adjust hex values to match your preferred theme.
3. Custom Key Bindings
Add custom bindings to your shell configuration file:
# Ctrl+T β fuzzy file finder
export FZF_CTRL_T_COMMAND="find . -type f 2>/dev/null"
# Alt+C β fuzzy directory navigator
export FZF_ALT_C_COMMAND="find . -type d 2>/dev/null"
# Ctrl+R β command history search with preview
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"4. Set a Default File Source with FZF_DEFAULT_COMMAND
By default, fzf uses find to list files. You can replace this with faster tools like fd or ripgrep:
# Using fd (faster alternative to find)
export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude .git"
# Using ripgrep
export FZF_DEFAULT_COMMAND="rg --files --hidden --follow --glob '!.git'"5. Persistent Configuration File
For Zsh users, you can store persistent fzf settings in a dedicated file:
echo "export FZF_DEFAULT_OPTS='--height 40% --reverse --inline-info --border'" >> ~/.fzf.zshEnsure this file is sourced in your ~/.zshrc:
[ -f ~/.fzf.zsh ] && source ~/.fzf.zshPractical fzf Workflow Examples
Here are ready-to-use functions you can add to your .bashrc or .zshrc:
Interactive cd with fzf
fcd() {
local dir
dir=$(find ${1:-.} -type d 2>/dev/null | fzf +m) && cd "$dir"
}Open Recent Files in vim
fvim() {
local file
file=$(find . -type f -name "*.${1:-*}" | fzf --preview 'cat {}')
[ -n "$file" ] && vim "$file"
}Search and Apply Git Stash
fstash() {
local stash
stash=$(git stash list | fzf | cut -d: -f1)
[ -n "$stash" ] && git stash apply "$stash"
}Troubleshooting Common fzf Issues
| Problem | Solution |
|---|---|
fzf: command not found | Ensure ~/.fzf/bin is in your $PATH; re-run ~/.fzf/install |
| Key bindings not working | Re-run the install script and confirm shell config is sourced |
| Slow performance on large directories | Set FZF_DEFAULT_COMMAND to use fd or rg instead of find |
| Colors not displaying correctly | Ensure your terminal supports 256 colors; add --color=always to preview commands |
| fzf not found after package install | Run source ~/.bashrc or open a new terminal session |
Why Your Hosting Environment Matters for Developer Productivity
A powerful terminal workflow like fzf is only as effective as the environment it runs in. Slow I/O, limited resources, or restricted permissions can undermine even the best tooling.
- For developers and sysadmins who need full control, AlexHost's VPS Hosting provides dedicated resources, root access, and the flexibility to install any tool without restrictions.
- For teams managing web applications, pairing your server with a VPS with cPanel gives you both terminal power and a graphical management interface.
- For projects requiring a domain and web presence, AlexHost's Domain Registration and Shared Web Hosting offer an affordable, fully managed starting point.
Conclusion
fzf is one of the most impactful tools you can add to your Linux terminal workflow. Its fuzzy-matching algorithm, real-time filtering, and seamless integration with shell commands make it an indispensable productivity multiplier β whether you're searching files, recalling commands, managing Git branches, or navigating remote servers.
Key takeaways from this guide:
- Install fzf via Git clone for the latest features, or use your package manager for simplicity
- Enable key bindings (
Ctrl+T,Ctrl+R,Alt+C) for instant access to fzf's most useful features - Combine fzf with
vim,ssh,git,kill, andfindusing command substitution - Customize appearance and behavior through
FZF_DEFAULT_OPTSand shell configuration - Use
--previewto turn fzf into a full-featured file browser
Start with the basics, gradually incorporate the integrations that match your workflow, and you'll quickly wonder how you ever managed the terminal without it.
on All Hosting Services
