Fzf - Fuzzy Finder Command-Line Tool

Learn how to use Fzf, a powerful command-line fuzzy finder, to quickly search and select files, commands, and more. Explore Fzf examples for efficient workflow.

Fzf - Fuzzy Finder Command-Line Tool

Fzf Command Examples for Enhanced Productivity

Fzf is an indispensable command-line utility that significantly boosts productivity by enabling rapid fuzzy searching and selection of files, commands, and more. This tool acts as an interactive filter, allowing you to quickly narrow down lists of items based on partial matches. Below are practical examples demonstrating how to leverage Fzf in your daily workflow.

Basic File Fuzzy Finding

The most common use case for Fzf is to fuzzy find files within the current directory. Simply running fzf will present an interactive list of files and directories, allowing you to type characters to filter them. Pressing Enter selects the highlighted item.

# To fuzzy find files in current directory
fzf

Opening Selected Files

You can combine Fzf with other commands to perform actions on the selected files. For instance, to open a file found with Fzf using your default editor or viewer:

# To fuzzy find a file and cat it
cat $(fzf)

Case Sensitivity Options

Fzf offers options to control case sensitivity during searches. Use -i for case-insensitive matching, which is often more convenient.

# Case sensitive search
fzf +i

# Case insensitve search
fzf -i

Multi-File Selection and Actions

Fzf's multi-select capability is powerful for batch operations. You can select multiple files using Tab and then pipe them to commands like rm.

# Select multiple files (TAB to select, Shift+TAB to un-select) to delete
rm -rf $(fzf --multi)

Previewing Files with Fzf

Enhance your search by enabling a preview window that shows the content or details of the currently highlighted item. This is incredibly useful for identifying the correct file without opening it.

# Run a preview command with fzf, specifiy a command inside the double quotes.
fzf --preview "file {}"

# Find files from find command and preview it with fzf
find . -type f -name "*.txt" | fzf --preview "head {}"

Customizing Fzf Appearance

Fzf allows for visual customization, such as adding a border around its interface for better clarity.

# Display border around fzf output 
fzf --border sharp

Outputting Selected Items

You can direct the output of selected items to a file, which is useful for scripting or logging.

# Output only selected files and pipe it to a file
find . -type f "*.txt" | fzf --multi > output.txt

Further Resources