locate is a system command used to build a file index. When we need to find a file, just type

locate xxx
It will search the entire system for files matching that name.

But on a new machine, when I locate a certain file, it always shows the following error message:

Bash
locate: can not stat () 
    `/var/lib/mlocate/mlocate.db': No such file or directory

Actually, if you just man it and look at the description, you can get some clues:

locate reads one or more databases prepared by updatedb(8) and writes file names matching at least one of the PATTERNs to standard output, one per line.

Its contents are actually stored in a database under /var/lib/mlocate/. If it hasn't been initialized, it will naturally throw an error. Just

Bash
updatedb

After the execution completes, check that directory

Bash
root@argcv ~]# ls -al /var/lib/mlocate/
total 10456
drwxr-x---  2 root slocate     4096 Jun 23 13:58 .
drwxr-xr-x 26 root root        4096 Jun 23 13:28 ..
-rw-r-----  1 root slocate 10698443 Jun 23 13:58 mlocate.db

Then it works normally...

References:

  1. 'locate' command not working [SOLVED]