locate是一个系统命令,用于建立文件索引,当我们需要寻找什么文件的时候,只要敲入

locate xxx

它就会搜索全系统中匹配这个名字的文件。 但是在某个新的机器里面,我locate某文件,始终显示如下的错误信息:

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

其实你只要man下它,看到description就可以知道一些端倪:

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.

它的内容其实是存储在/var/lib/mlocate/下的一个数据库里面,而没有初始化,自然就会出错,只要

updatedb

等执行完毕,检查那个目录

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

然后就正常了...

References:

  1. 'locate' command not working [SOLVED]
Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

4 Comments

starry · July 1, 2014 at 01:05

Google Chrome 35.0.1916.153 Google Chrome 35.0.1916.153 Windows 7 x64 Edition Windows 7 x64 Edition

吊炸了还有自己的技术博客。。。

Leniy · June 27, 2014 at 17:05

Google Chrome 35.0.1916.114 Google Chrome 35.0.1916.114 GNU/Linux GNU/Linux

竟然还有这个命令,好犀利

    yu · June 27, 2014 at 17:08

    Google Chrome 35.0.1916.153 Google Chrome 35.0.1916.153 Mac OS X  10.9.3 Mac OS X 10.9.3

    @Leniy 一直有,内建索引查文件速度快多了.

    休息了好久最近终于要活过来了么?

      Leniy · June 27, 2014 at 20:37

      Google Chrome 33.0.1750.27 Google Chrome 33.0.1750.27 Windows 7 Windows 7

      @Yu Jing 没有休息啊,连续工作几个月没有休息日了。
      最近又生孩子了,更是没有时间。

Leave a Reply to starry Cancel reply

Your email address will not be published. Required fields are marked *