locate is a system command used to build a file index. When we need to find a file, just type
locate xxxBut 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 directoryActually, 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
updatedbAfter 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.dbThen it works normally...
Comments · 4