Linux Format

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-insensitiv­e search. The alternativ­e 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 informatio­n. It also enables you to specify which directorie­s 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 ‘*someotherf­ile*’ find /usr -maxdepth 2 -iname ‘*whatfile*’

The first line starts the search in the current directory, and descends into all sub-directorie­s. The second starts in /usr instead, and performs caseinsens­itive searching. The third line does the same, but descends a maximum of two directorie­s.

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 directorie­s: 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.

Newspapers in English

Newspapers from Australia