locate命令执行报错解决办法

环境:CentOS Linux release 7.8.2003 (Core)
背景:想执行locate命令时报错

[root@Centos7 ~]# locate
-bash: locate: command not found

这里注意是需要安装mlocate,而不是locate:

[root@Centos7 ~]# yum search locate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.ustc.edu.cn
==================================================================== N/S matched: locate ====================================================================
mlocate.x86_64 : An utility for finding files by name
perl-File-ShareDir.noarch : Locate per-dist and per-module shared files
which.x86_64 : Displays where a particular program in your path is located

  Name and summary matches only, use "search all" for everything.
[root@Centos7 ~]# yum install mlocate -y

安装完成后,发现又有报错提示:

[root@Centos7 ~]# locate chage
locate: can not stat () '/var/lib/mlocate/mlocate.db': No such file or directory
[root@Centos7 ~]# locate who
locate: can not stat () '/var/lib/mlocate/mlocate.db': No such file or directory

需要执行如下命令:

[root@Centos7 mlocate]# updatedb

updatedb的man文档描述如下:

NAME
       updatedb - update a database for mlocate

SYNOPSIS
       updatedb [OPTION]...

DESCRIPTION
       updatedb  creates or updates a database used by locate(1).  If the database already exists, its data is reused to avoid rereading directories that
       have not changed.

       updatedb is usually run daily by cron(8) to update the default database.

再次运行locate命令已经正常:

[root@Centos7 mlocate]# locate chage
/usr/bin/chage
/usr/sbin/lchage
/usr/share/man/de/man1/chage.1.gz
/usr/share/man/fr/man1/chage.1.gz
/usr/share/man/it/man1/chage.1.gz
/usr/share/man/ja/man1/chage.1.gz
/usr/share/man/man1/chage.1.gz
/usr/share/man/man1/lchage.1.gz
/usr/share/man/pl/man1/chage.1.gz
/usr/share/man/ru/man1/chage.1.gz
/usr/share/man/sv/man1/chage.1.gz
/usr/share/man/tr/man1/chage.1.gz
/usr/share/man/zh_CN/man1/chage.1.gz

参考文档:
https://blog.csdn.net/webmater2320/article/details/79081948

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值