红联Linux门户
Linux帮助

Linux/Centos在用搜索命令locate时command not found问题

发布时间:2017-06-21 11:26:50来源:linux网站作者:Jolly_xue
在用locate查找命令找文件时提示如下:
-bash: locate: command not found
 
所以就想着是不是locate要yum来安装才可以呢,于是:
[root@localhost ~]# yum install locate
结果是No package locate available
 
接着就updatedb试试,提示:
-bash:updatedb:command not found
 
网上查了一下要先安装mlocate相应的包才可以,以前是slocate现在已被mlocate取代。
 
故:[root@localhost ~]# yum -y install mlocate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mlocate.x86_64 0:0.22.2-6.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
Package  Arch  Version  Repository  Size
Installing:
mlocate  x86_64  0.22.2-6.el6  base  86 k
Transaction Summary
Install       1 Package(s)
Total download size: 86 k
Installed size: 279 k
Downloading Packages:
mlocate-0.22.2-6.el6.x86_64.rpm  |  86 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mlocate-0.22.2-6.el6.x86_64  1/1
Verifying  : mlocate-0.22.2-6.el6.x86_64  1/1
Installed:
mlocate.x86_64 0:0.22.2-6.el6
Complete!
 
安装成功!执行locate passwd来搜索文件还是有报错:
[root@localhost ~]# locate passwd
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
 
还要使用updatedb命令来创建locate命令依赖的数据库:
[root@localhost ~]# updatedb
 
下面就可以使用locate命令了。
 
本文永久更新地址://m.ajphoenix.com/linux/31637.html