Search for files in Linux using the locate command
In most Linux distributions, you will find a command called locate which can be used to find any file on your system for which you have read permissions. The Linux locate command consults a database “/var/lib/mlocate/mlocate.db” and returns a list of all pathnames containing a certain group of characters.
Here is how you can use locate command to search a particular file.
Search for a file or directory named mydata
$ locate mydata
Usually what happens is locate will list all the files which have mydata in its name such as :
/usr/docs/mydata/somefile.html /home/username/mydata/myfile.txt /home/username/mydata.txt /home/username/Desktop/mydata
If you want to search for a file or directory named exactly mydata, then use the -b option as follows :
$ locate -b '\mydata' /home/username/Desktop/mydata /home/username/mydata/ /usr/docs/mydata/
In the above command, since ‘\‘ is a globbing character, this disables the implicit replacement of “mydata” by “*mydata*“.
The locate database is maintained by a command called updatedb. It is usually executed once a day by Linux distributions. For this reason, locate is very fast but useful only in finding files that are at least one day old. Of course nothing is stopping you from running the updatedb command yourself prior to using the locate command. But to use updatedb command you need to have root privileges.

