July 15, 2002 Flattr this

Mac OS X FAQ: Searching for files using the command line


Chris Kurylak recently asked:
    "I was wondering if you could tell me how can i search for files using the command line? It drives me crazy that the gui does not show everything on the system unless you first know where to look."
Well, this is an easy one: there's the find command.

If you type man find in Terminal.app, it'l show you some help.

Here are some Examples:
find . -name "*test.pl" -print will search for any filename which ends in "test.pl" in the current directory (the period "." after the find command stands for the current working directory) and all it's subdirectories.

find / -name "*test.pl" -print will search for any filename which ends in "test.pl" in the servers root directory (the slash "/" after the find command stands for the root directory - similar to "cd /") and all it's subdirectories.

Let's say you want to find any html file anywhere on your server (incl. any mounted volumes) this would be find / -name "*.html" -print

And to limit this to html files which have been modified longer than 3 days ago, this little voodoo will help:
find / -name "*.html" -mtime +3 -print
Note: funny enough, there is no Creation-Time on UNIX.
There are plenty of tips on the find command available through google.

Posted in: by seiz | Comments ()