locate命令查找文件比find速度快很多,locate是在linux下实现快速查找文件的工具.相应的windows下有everything功能也很强大.
[root@wuzhigang lib]# updatedb
-bash: updatedb: command not found原来是服务器中没有安装mlocate
[root@wuzhigang lib]# yum install mlocate
Loaded plugins: fastestmirror, refresh-packagekitRepository base is listed more than once in the configurationRepository updates is listed more than once in the configurationRepository extras is listed more than once in the configurationRepository centosplus is listed more than once in the configurationRepository contrib is listed more than once in the configurationLoading mirror speeds from cached hostfile * base: mirrors.163.com * extras: ftp.sjtu.edu.cn * nux-dextop: li.nux.ro * updates: mirrors.163.comSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package mlocate.x86_64 0:0.22.2-4.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================= Package Arch Version Repository Size=======================================================================================================================================Installing: mlocate x86_64 0.22.2-4.el6 base 86 kTransaction Summary=======================================================================================================================================Install 1 Package(s)Total download size: 86 kInstalled size: 279 kIs this ok [y/N]: yDownloading Packages:mlocate-0.22.2-4.el6.x86_64.rpm | 86 kB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing : mlocate-0.22.2-4.el6.x86_64 1/1 Verifying : mlocate-0.22.2-4.el6.x86_64 1/1 Installed: mlocate.x86_64 0:0.22.2-4.el6 Complete!
安装成功了,现在使用 updatedb 命令来创建locate命令依赖的数据库。
[root@wuzhigang lib]# updatedb[root@wuzhigang lib]# locate passwd
整个locate工作其实是由四部分组成的:
- /usr/bin/updatedb
- /usr/bin/locate or mlocate
- /etc/updatedb.conf
- /var/lib/mlocate/mlocate.db
updatedb主要用来更新数据库,这个工作是通过crontab自动完成的.
mlocate/locate是作来完成查询功能的程序;updatedb.conf是配置要查询哪些目录, 哪些文件;mlocate.db则是存放文件信息的文件;