Does anybody know a way to perform a quick fuzzy search from linux console?
Quite often I come accross situation when I need to find a file in a project but I don't remember the exact filename. In Sublime text editor I would press Ctrl-P and type a part of the name, which will produce a list of the files to select from. That's an amazing feature I'm quite happy with. The problem is that in most cases I have to browse a code in a console on remote machines via ssh. So I'm wondering is there a tool similar to "Go Anywhere" feature for Linux console?
Case insensitive find of filenames containing
foo
.You could use find like this for complex regex:
find . -type f -regextype posix-extended -iregex ".*YOUR_PARTIAL_NAME.*" -print
Or this for simplier glob-like matches:
find . -type f -name "*YOUR_PARTIAL_NAME*" -print
Or you could also use find2perl (which is quite faster and more optimized than find), like this:
find2perl . -type f -name "*YOUR_PARTIAL_NAME*" -print | perl
If you just want to see how Perl does it, remove the
| perl
part and you'll see the code it generates. It's a very good way to learn by the way.Alternatively, write a quick bash wrapper like this, and call it whenever you want:
Name this something like
qsearch
and then call it like this:qsearch . something
You can try c- (Cminus), a fuzzy dir changing tool of bash script, which using bash completion. It is somehow limited by only matching visited paths, but really convenient and quite fast.
GitHub project: whitebob/cminus
Introduction on YouTube: https://youtu.be/b8Bem53Cz9A
I usually use:
From a directory above where I expect the file to be - the higher up you go in the directory tree, the slower this is going to go.
When I find the the exact file name, I use it in find:
This could be collapsed into one line:
(I found a problem with ls and grep being aliased to "--color=auto")
You may find fzf useful. It's a general purpose fuzzy finder written in Go that can be used with any list of things: files, processes, command history, git branches, etc.
Its install script will setup
CTRL-T
keybinding for your shell. The following GIF shows how it works.