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

猜你喜欢

转载自blog.csdn.net/szuwangjl/article/details/111788745