Search for a File in Linux


Linux

Locating any file on a linux operating system can be done quickly from the command line.

Step 1

Index your file system with updatedb. This makes a list of files so that later searches won’t have to look in the entire span of directories each time. The process can later be added to a cronjob and happen automatically. Run the Command:

prompt$: updatedb

Step 2

Once the directory has been updated, the way to find the location of a desired file is with locate. An alternative is the find command, which can take a longer time to finish searching the entire system.

prompt$: locate filename

Its that easy, and to refine the search results you can add part of the path or use grep. Here is an example using part of the path to only find files named config.conf in the apache directory.

prompt$: locate apache/config.conf

Filter Results

Narrowing down results with grep can prevent the screen from being filled up with results, as in this case many files contained the term “nx”

Example:

To find where nxclient’s dsa key is hiding.

locate nx | grep key | grep dsa

Output:

/etc/nxserver/client.id_dsa.key
/etc/nxserver/server.id_dsa.pub.key

Leave a Reply