47

I wanted to install the command locate, which is available via sudo apt-get installmlocate.

However, I first ran sudo apt-get installlocate which seems to have installed something else.

Typing the command locate <package> however seems to call upon mlocate.

What is the package locate, and can (should) it be safely removed?

P A N
  • 1,761
  • 4
  • 19
  • 23
  • 2
    I believe mlocate was the replacement for the original locate, But That was 15 years ago, and probably, one package is an alias or referer to the other. There is another variant, "slocate" which observed a file's visibility based on user permissions, but I haven't see. That in a long time – Otheus Mar 30 '16 at 17:26

2 Answers2

59

The locate package is the implementation of locate from GNU findutils. The mlocate package is another implementation of the same concept called mlocate. They implement the same basic functionality: quick lookup of file names based on an index that's (typically) rebuilt every night. They differ in some of their functionality beyond basic usage. In particular, GNU locate builds an index of world-readable files only (unless you run it from your account), whereas mlocate builds an index of all files but only lets the calling user see files that it could access. This makes mlocate more useful in most circumstances, but unusable in some unusual installations where it isn't run by the system administrator (because mlocate has to be setuid root), and a security risk.

Under Debian and derivatives, if you install both, locate will run the mlocate implementation, and you need to run locate.findutils to run the GNU implementation. This is managed through alternatives. If you have both installed, they'll both spend time rebuilding their respective index, but other than that they won't conflict with each other.

  • 17
    You neglected to mention mlocate's main feature, from which it gets its name ("merging locate"): It provides a version of updatedb that reuses its old index to improve update performance by only querying lists of files/subdirectories for directories where the ctime has changed. – ssokolow Jul 17 '18 at 04:08
  • "GNU locate builds an index of world-readable files only" are you sure? I found names of a lot of files via locate as regular user, where I had no permissions to in the end – rubo77 Jan 01 '22 at 22:48
  • @rubo77 Your locate is probably mlocate and not GNU locate. – Gilles 'SO- stop being evil' Jan 02 '22 at 08:35
11

mlocate is a newer implemenation of locate. Once you install mlocate it

will change the /usr/bin/locate binary to point to mlocate via the alternatives mechanism.

That is why you get mlocate behaviour if you install in that order.

Details can be found here

Anthon
  • 79,293
  • 2
    In fact, I never installed mlocate, but on my Ubuntu 16.04 system, /usr/bin/locate -> /etc/alternatives/locate -> /usr/bin/mlocate – cayhorstmann Nov 08 '17 at 04:22