|Tip 358||Search for System Files|
OS X works hard to keep users separate from system files, and this can make tracking down files outside of your Users folder tricky. However, here are two ways to do so.
In terms of files, Spotlight searches only those in your personal User folder. This is very limiting, especially if you’re used to the more wide-ranging search tools of other operating systems that can be used to track down system files too.
There’s no way to make the main Spotlight tool search for system files, but you can use Finder’s Spotlight search tool to uncover them. Here’s how.
Hit Option+Command+Space to reveal the Finder Spotlight window, no matter which app you’re currently using (if that key combination doesn’t work, try Control+Option+Space).
Click the plus button next to the Save button. This will add a new filter for the search. Click the Kind drop-down list, and select Other.
In the list that appears, put a check next to System Files, and click the OK button. Back in the Finder window, change the drop-down list next to System Files Are Included.
Finally, type your search query into the Spotlight field at the top right of the Finder window, and ensure This Mac is selected alongside the Search heading. After a few seconds, you should start seeing the results, which will include system files.
If you click the Save button, located just beneath the search field, you can add the system file search to the sidebar of Finder, to be used again (just select it each time and type the search query as described earlier). Otherwise, you’ll have to repeat these steps each time you want to search for a system file.
Using the locate Command
As a version of Unix, OS X comes complete with the locate command, which can be used at the command line to track down any kind of file—a system file or a user data file. locate relies on a database of file locations and names that are periodically and automatically updated (as such, unlike Spotlight, locate knows only the names of files and doesn’t index their contents).
However, locate isn’t activated by default. You can do so by opening a Terminal window (open Finder, select the Applications list, and then in the list of applications double-click Terminal within the Utilities folder) and typing the following, entering your login password when prompted:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
This needs to be done only once.
To use locate in the future, just specify the search query after typing locate -i. For example, to search for the location of the hosts file, you could type the following:
locate -i hosts
The -i flag tells locate to ignore case sensitivity. Note that it will take some time for the initial locate database to be created, in which case you’ll see error messages when you try to use the locate command.
To deactivate locate, type the following, which will deactivate the periodic updating of the locate database:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.locate.plist