23

I go to use the updatedb command to update the index and I get

updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'

fyi The locate command is working, e.g.

$ locate Index.xml
/usr/share/mysql/charsets/Index.xml
durrantm.../durrantm$ 

How can I overcome this issue when trying to run updatedb?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232

2 Answers2

41

You have to run the updatedb command as the super user. For example,

sudo updatedb
Manula Waidyanatha
  • 2,263
  • 20
  • 12
  • Once created, can the database be updated by a regular user (_e.g._ from `crontab`) without super-user privileges? – holdenweb Dec 15 '15 at 12:01
  • 1
    The update db creates the cache file in /var/cache/locate/locatedb, which is only writable by root. So regular user cannot run the command. But it is possible to create a file in different location which is writable by a regular user. (But the problem is regular users cannot read the whole file system) – Manula Waidyanatha Dec 15 '15 at 12:11
  • Even sudo didn't work in my case :/ @ManulaWaidyanatha – sh.3.ll May 09 '20 at 17:41
5

If you lack time and want to locate a file, you don't need to sudo updatedb in order to update cache. Instead, you can use locate -e filename to skip cache.

Shuhua Fan
  • 51
  • 1
  • 1
  • If you don't have the ability to sudo or don't have mlocate installed, you can use this to find files in the folders where you have permission to look (substitute `file*.name` with any wildcard-capable filename that you're looking for): `find / -iname "file*.name" -print 2>/dev/null` – Peter Kionga-Kamau Apr 11 '22 at 15:21