Why fzf is my “indispensable” tool
Searching for a config file buried deep within the /etc clutter or trying to recall a Docker command from last week can be incredibly frustrating. The traditional approach is using history | grep or find. These methods work, but they become painfully slow once your command history exceeds 5,000 lines.
I have been using fzf on all my production servers and personal machines for over six months now. Looking back, I regret not discovering it sooner. fzf is a command-line fuzzy finder written in Go, which is extremely lightweight and offers near-instant response times.
The key selling point is its “fuzzy search” mechanism. You only need to type a few approximate characters instead of the exact string, and the results appear in real-time. In my experience managing systems, fzf neatly handles three main tasks: retrieving command history, opening files quickly, and killing hung processes.
How to install fzf to unlock all its features
While distributions like Ubuntu or Debian include fzf in their official repositories (sudo apt install fzf), I still prefer installing it via Git. This ensures you have the latest version and automatically enables the highly convenient keyboard shortcut scripts.
# Clone the repo to your home directory
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
# Run the installation script
~/.fzf/install
During installation, the script will prompt you with three choices; type Y for all of them:
- Fuzzy auto-completion: Enables typing
cd **[TAB]to find directories quickly. - Key bindings: Activates shortcuts like CTRL-R and CTRL-T.
- Update shell configuration: Automatically adds the necessary configuration to your
.bashrc.
Once installed, run source ~/.bashrc to apply the changes to your current session.
Keyboard shortcuts to work like a pro
Using default shortcuts
Here are the three shortcuts I use at least 100 times a day:
- CTRL-R: A total replacement for Bash’s outdated history search. Just type “nginx reload,” and fzf will filter exactly the command you need in a flash.
- CTRL-T: Quickly find a file to insert into your current command. For example, type
vim [CTRL-T], select your file, and the filename will automatically appear after the vim command. - ALT-C: Rapidly navigate into subdirectories. You don’t need to type long paths anymore; just pick the directory from the fzf list.
Integrate fd for 10x faster file scanning
By default, fzf uses the find command, which can be slow and often scans unnecessary directories like .git or node_modules. I usually replace it with fd to boost scanning speeds on large projects.
Install fd with: sudo apt install fd-find. Then, paste the following code at the end of your .bashrc file:
# Use fd instead of find to ignore hidden files and .git directories
export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
Preview Window: View file content without opening
Instead of opening every file to check if it’s the one you need, you can use the preview feature. To get a beautiful interface with syntax highlighting, you should also install bat.
# Configure Preview for the first 500 lines of a file for CTRL-T
export FZF_CTRL_T_OPTS="--preview 'bat --color=always --line-range :500 {}'"
Now, whenever you press CTRL-T, a preview pane will appear on the right showing the file’s content intuitively.
Quickly handle hung processes
When a server is lagging, instead of typing ps aux | grep... and manually copying PIDs, I use this small function in my .bashrc to “kill” processes in seconds:
fkill() {
local pid
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
Just type fkill, use the arrow keys or type the process name, and hit Enter. You can also use the Tab key to select multiple processes at once.
Practical experience after 3 years of use
Mastering fzf isn’t hard, but here are a few tips to make it smoother across all environments:
1. System Resources: fzf is extremely RAM-efficient, typically using less than 20MB even when handling tens of thousands of files. You can safely install it on low-spec VPS instances.
2. Handling Massive Directories: If you work with directories containing over 100,000 files, ensure you are using fd and excluding virtual paths like /proc or /sys to avoid search hangs.
3. SSH Considerations: When remoting into a new server, if fzf isn’t installed, your shortcuts won’t work. I usually pre-install fzf on my main management servers to keep my workflow consistent.
fzf isn’t just for Bash. If you use Vim, there are powerful plugins available for source code searching. However, even just using fzf on the command line will save you at least 30 minutes a day on repetitive, mundane tasks.
Try spending a week getting used to CTRL-R and CTRL-T. I’m confident you’ll never want to go back to manual typing again.

