This is where Adam Spooner writes.

Quick Unix Tip: Find Files by Name

Posted on

I frequently need to find files whose name and location I only partly remember. I could use Spotlight, but I find it clunky. Besides, I’m usually at a command prompt which means this tool is only a few keystrokes away:

find . -iname \*pattern\*

Let’s dissect it. The name of the command is find, the .—say, “dot”—means “start walking the file hierarchy from my current location”, -iname tells find to look at files names and ignore the case—case insensitive, and \*pattern\* lets find know what string or pattern we’re after.

I have a large collection of books in PDF I frequently reference. I rarely remember the name of the book, but I know it has “PHP” in its title. So, I cd to my directory of books and enter find . -iname \*php\*, and I’m given a list of books whose titles contain “PHP”. Alternatively, I could’ve entered find path/to/my/books/ -iname \*php\*.