Fuzzy Search Directory in Terminal

Sep 8, 2020 min read

Sometimes we need to find a file or folder in a directory, but struggle to remember the exact name that we’re trying to find. Tab auto-completion is great but it also assumes that we know the first few letters of the thing we need to find. Here is a simple terminal command that will do a “fuzzy” search of the current directory. If you’re not aware a fuzzy search is one that looks through an entire word or phrase for a matching value. The search term may appear anywhere in the title of the file or folder.

ls | grep -i <search term>

Example

ls | grep -i scrap

If you’re a little more daring, you can search all nested folders recursively by using the -R flag. (Use this with caution.)

Recursive Example

ls -R | grep -i scrap

The command breakdown:

ls: List all files and folders by name in the directory |: The pipe command passes data received from left side to the right side of the argument grep: Use to search the results
-i: Lists all files which contain the search term