Table of Contents
mlocate.db No Such File or Directory
In some cases, you might see the below error while trying to search a file/directory on your Linux server using locate command. Even the mlocate package is installed on your system.
The error show that mlocate.db file is missing on the server.
# locate php.ini
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
You would get the above error if you were running locate command for the first time or if it is a newly setup Linux server. So, you need to update the updatedb.
The default database storage location is /var/lib/mlocate/. As you can see there’s no database in that location.
[root@centos7 ~]# ls -l /var/lib/mlocate/
total 0
To fix it, you must first run command on the server so that locate will store all the file location in mlocate.db.
sudo updatedb
Once the database is updated, you can see it in /var/lib/mlocate directory.
[root@centos7 ~]# ls -l /var/lib/mlocate/
total 836
-rw-r----- 1 root slocate 854125 Dec 16 10:19 mlocate.db
Now, you can start searching files using locate command after updatedb is completed. Database file is automatically created when we ran updatedb command.
# updatedb
# locate php.ini
/etc/opt/remi/php74/php.ini
/opt/remi/php74/root/usr/share/doc/php74-php-common-7.4.32/php.ini-development
/opt/remi/php74/root/usr/share/doc/php74-php-common-7.4.32/php.ini-production
This database file contains details of location of all files on your Linux server. When you search a file locate command will search this database and provides the file location immediately.
# locate nginx.conf
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
Not a reader? Watch this related video tutorial: