1. 程式人生 > 其它 >locate命令執行報錯解決辦法

locate命令執行報錯解決辦法

技術標籤:Linux

環境:CentOS Linux release 7.8.2003 (Core)
背景:想執行locate命令時報錯

[[email protected] ~]# locate
-bash: locate: command not found

這裡注意是需要安裝mlocate,而不是locate:

[[email protected] ~]# 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.
[[email protected] ~]# yum install mlocate -y

安裝完成後,發現又有報錯提示:

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

需要執行如下命令:

[[email protected] 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命令已經正常:

[[email protected] 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