Finding Files from the Command Line

Searching the file system for a specific document or file is easy and very fast. Though most users are best served using Spotlight from the menubar, there are times when either Spotlight isn’t working, you need more paramaters, you’re working in the Terminal, operating with a remote machine, or perhaps just would like to use an alternative search function.

You’re in luck, we’ll show you how to find files and folders directly from the command line using two different tricks. The first method is operating system agnostic, meaning you’ll be able to use the search function with Mac OS X, Linux, BSD, and many other unix variations, whereas the second trick for searching utilizes a Mac-only model of finding files from the command line. Let’s read on and learn how to use these great abilities.

Searching For Files from Command Line with find

The find command is very fast and easy to use, it’s straight from the unix world and as such works in Linux as well as Mac OS X. If you’re looking to learn things that are consistent across platforms, find is a good choice.

At it’s most basic, find can be used like so:

find path parameters

For example, you can locate anything within the user home directory containing “screen” in it’s name with the following:

find ~ -iname "screen*"

You may want to pipe the results to more if you’re expecting a large return, like so:

find ~ -iname "screen*" | more

Of course you can also find specific files that are buried somewhere in a directory. For example, looking in the user library folder for a specific plist file:

find ~/Library/ -iname "com.apple.syncedpreferences.plist"

You will need to prefix find with ‘sudo’ to search root directories and outside of the current user privileges. find also supports expressions, allowing you to search for very specific matches, wildcards, sequences, and other advanced options.

find is very powerful but it’s power quickly brings with it some complexity, as a result the classic mdfind command is probably better for more novice command line users.

This website and third-party tools use cookies for functional, analytical, and advertising purposes. By continuing to browse the site, closing this banner, scrolling this webpage, or clicking a link, you agree to these cookies. You can review our privacy policy for additional information.I AcceptPrivacy Policy