Tool called fzf - command line fuzzy file finder - very cool

5 views
Skip to first unread message

Tom

unread,
Feb 23, 2024, 12:07:55 PMFeb 23
to Milwau...@googlegroups.com
I just discovered a tool called fzf - fuzzy finder. Since I spend my life mostly on the command line, it's a really valuable tool. If you're a 90% GUI person, or more, maybe not as useful to you.
 
Nice writeup here:
 
I installed it thusly:
dnf -y install fd-find fzf bat
 
You Ubuntu fans would do something similar with apt-get, or course.
 
I also like the bat utility, which replaces cat and less - the version I'm using is bat-0.11.0-3.module_f31+5338+1c55392b.x86_64 but ymmv.
 
Then, to make it yet more helpful, a created a script called fzy in /usr/local/bin
 
#!/bin/bash
# REQUIRES: the fzf package, and bat
#
ME=$(basename $0)
echo "${ME}:Fuzzy find with preview. Usage: $ME filenamefragment"
echo " For reasonable results, start in a parent directory of what you're looking for- not /"
echo " For tighter matching, specify -e on the command line."
if [[ -z $1 ]]; then
    exit 1
fi
fzf -q$1 $2 $3 $4 $5 $6 $7 $8 $9 --preview 'bat --color=always {}'
 
It's WONDERFUL to have a simple file finder tool with on-screen preview to make sure you're looking at the right file.
 
The last line:

gives the -q option to specify what to search for

lets you pass whatever random options you like to the program, like -e maybe? See the man page for fzf

specifies what file previewer to use. If you don't like 'bat' or can't get it, use 'less' or something else.

 
Don't laugh at my code-- it was a fast cobble-up to address a need.
 
You can use the script or the fzf tool directly. When you scroll to to the match you want, and press enter, fzf exits and sends the filename to stdout you selected, so you can easily use this tool (or my script) in a pipeline. Or press the ESC key for no output.
 
Note that fzf matches the letters in what you type (or in the case of my script, give on the command line) so you will get a LOT of results. If you search for fzy, you'll get fuzzy, fizzy, fozygizwonkus, and everything else that matches those letters. That's why the -e switch is useful-- it limits the search to those letters, in that order, together, but potentially embedded in any other name.
 
Note also that I have a lot of file and a lot of NAS devices to store them. If I start a search in / (top level directory) it's almost impossible enter a specific enough search string to avoid coming back with under 88,984 matches. That's an actual number I got from trying it. So I either use -e or start in a directory like /usr or /vscode, or someplace else that will not include a NAS mount. Otherwise it can take 10 minutes to find all possible matches. For the record, I searched for a filename containing the word 'catalog'
 
The same search using the -e switch came up with under 1000 matches.
 
The article has a note about replacing 'find' with 'fd' which is faster, and that might help.
 
Have fun!
 
 
 
 

Sean Malloy

unread,
Feb 23, 2024, 12:32:12 PMFeb 23
to Milwau...@googlegroups.com
fzf and bat are great. I use both of these tools.

--
Sean Malloy

--
Homepage: http://www.milwaukeelug.org/home
This forum online: https://groups.google.com/forum/#!forum/MilwaukeeLUG
---
You received this message because you are subscribed to the Google Groups "Milwaukee Linux User's Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MilwaukeeLUG...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/MilwaukeeLUG/5701.1350833286.1708708067%40gmail.com.
Reply all
Reply to author
Forward
0 new messages