A QUICK REFERENCE TO FINDING FILES
Linux has two main tools for finding files: locate and find. The former works by keeping a database of files on your system. It’s fast, but limited to files that were present when the database was last updated. Most distros install a cron script to keep the file database up to date. Locate is also limited to searching on file names. To use it, type: locate somefile
Add -i for a case-insensitive search. The alternative is find, which searches the filesystem directly. It’s slower, and can only search areas the user has permission to read, but provides completely up-to-date information. It also enables you to specify which directories to search or exclude, and search on properties other than the file name, such as the file’s owner or creation date. find -name ‘*somefile*’ find /usr -iname ‘*someotherfile*’ find /usr -maxdepth 2 -iname ‘*whatfile*’
The first line starts the search in the current directory, and descends into all sub-directories. The second starts in /usr instead, and performs caseinsensitive searching. The third line does the same, but descends a maximum of two directories.
With more options, find is a far more flexible option, but locate is great for quick searches. You can pipe locate’s output through grep to search specific directories: locate -i myfile | grep /home/
Note also that locate searches for a substring, whereas find looks for an exact match, hence the use of * as a wildcard.