fzf (fuzzy finder) is a command-line fuzzy finder for filtering and selecting from lists. Extremely fast and versatile for navigating files, command history, and more.
Basic Usage
- fzf - Fuzzy find from stdin
- ls | fzf - Fuzzy find from file list
- find . -type f | fzf - Fuzzy find from find results
- fzf <dir> - Fuzzy find files in directory
Interactive Commands
- Ctrl+C, Esc - Exit
- Enter - Select and exit
- Tab - Select multiple items (multi-select)
- Shift+Tab - Unselect
- Up/Down Arrow or Ctrl+P/N - Navigate up/down
- Page Up/Down or Ctrl+V/B - Navigate page up/down
- Alt+Up/Down - Navigate half page up/down
- Ctrl+A - Select all
- Ctrl+D - Deselect all
- Ctrl+T - Toggle all
- Ctrl+L - Clear input
- ? - Toggle preview window
- Alt+W - Toggle preview wrap
- Alt+? - Toggle help
Search Patterns
- `word` - Match lines containing word
- `'word` - Exact match (disables fuzzy matching)
- `^word` - Prefix match (starts with word)
- `word$` - Suffix match (ends with word)
- `!word` - Negation (exclude lines with word)
- `'word1 | 'word2` - OR operator
- `word1 word2` - AND operator (both must match)
Preview Window
- fzf --preview='cat {}' - Preview file contents
- fzf --preview='head -100 {}' - Preview first 100 lines
- fzf --preview='ls -lah {}' - Preview file details
- fzf --preview-window=right:40% - Custom preview window size
- fzf --preview-window=hidden - Hide preview initially
- ? - Toggle preview (in fzf)
Common Use Cases
File Navigation
- fzf - Find files in current directory
- find . -type f | fzf - Find all files recursively
- fzf --type f - Files only
- fzf --type d - Directories only
Command History
- history | fzf - Search command history
- Ctrl+R - fzf search through history (if configured)
Process Selection
- ps aux | fzf - Search and select process
- ps aux | fzf | awk '{print $2}' - Get PID from selection
Git Operations
- git log --oneline | fzf - Browse git commits
- git branch | fzf - Select branch
- git stash list | fzf - Select stash
Shell Integration
Bash/Zsh Key Bindings
Add to `~/.bashrc` or `~/.zshrc`:
# Use fzf for Ctrl+R history search
if command -v fzf >/dev/null 2>&1; then
source /usr/share/fzf/shell/key-bindings.bash # or .zsh
fi
After setup:
- Ctrl+R - Search command history
- Ctrl+T - Find and insert file path
- Alt+C - Change directory (cd)
Fish Shell
fzf_key_bindings
Useful Aliases
Add to your shell config:
# File operations
alias fcd='cd $(find . -type d | fzf)'
alias fvim='vim $(fzf)'
alias fcat='cat $(fzf)'
# Git with fzf
alias fco='git checkout $(git branch | fzf | sed "s/^..//")'
# Process kill
alias fkill='kill -9 $(ps aux | fzf | awk "{print \$2}")'
Advanced Options
- fzf --height 40% - Set height
- fzf --reverse - Reverse layout (top to bottom)
- fzf --border - Show border
- fzf --header='Select file:' - Custom header
- fzf --multi - Enable multi-select
- fzf --bind='ctrl-a:select-all' - Custom key bindings
- fzf --exact - Exact match mode
- fzf --extended - Extended search mode (default)
Configuration
Config File Location
- `~/.fzfrc` - fzf configuration
- `~/.fzf.bash` - Bash integration (if installed)
- `~/.fzf.zsh` - Zsh integration (if installed)
- `/usr/share/fzf/` - Default installation directory
Example Configuration
# fzf options
export FZF_DEFAULT_OPTS='--height 40% --reverse --border'
export FZF_DEFAULT_COMMAND='fd --type f' # Use fd instead of find
export FZF_CTRL_T_COMMAND='fd --type f'
export FZF_CTRL_T_OPTS='--preview "bat --color=always --style=numbers {}"'
Tips
- Use single quotes `'word'` for exact matches when fuzzy matching fails
- Combine with other tools using pipes: `find . | fzf | xargs vim`
- Use preview window to see file contents before selecting
- Configure shell bindings for Ctrl+R, Ctrl+T, Alt+C
- Use multi-select (Tab) to select multiple files
- Install ripgrep or fd for faster file finding with fzf
- Customize colors and layout with FZF_DEFAULT_OPTS
- Use fzf in scripts for interactive selection
- Combine with vim (fzf.vim plugin) for file navigation
- Great for browsing logs: `tail -f /var/log/syslog | fzf`