1

I often use locate as a command to find stuff system-wide. However, I find it very annoying that the osx version of locate doesn't seem to have the -b option to match the basename only; and so prints all the content of every folder that matches the query. It also doesn't have the -e option for checking whether the files have been removed since the last update of the database.

On my linux machine (Ubuntu 20.04), those options, and many others, exist. The man page for it shows the date Sep 2012, while the Mac shows August 2006.

Are these two entirely different programmes or different versions of the same? How do I get the better locate on Mac?

Martino
  • 111

2 Answers2

3

Mac BSD and GNU Linux are shipping different "locate" program. Locate has advantages over find, for pros and cons I will refer you to: This page. However, there are some other options on mac like:

mdfind -name file.pdf

For archlinux, I am using plocate (compatible with mlocate).

How do I get the better locate on Mac?

Locate is only report files that are present in the database (if I am not mistaken it gets updated once a week), you can also use find with specified directory. Indexing is the key.

Good luck

kasa
  • 99
  • Thank you, I knew about find but was asking about locate specifically. Nevertheless your answer pointed me in the right direction. – Martino Feb 11 '21 at 09:13
0

Kasa's answer pointed me to the right direction: these are two different programmes. The Linux locate is actually mlocate, and can be installed on Mac with some struggles, as some people have done, while the Mac locate is a different and older version. More about the difference in this answer.

However, the easier way is to use mdfind, which is already installed on Mac (it's probably the thing behind Spotlight) and follows the same principles and seems to be better than the old BSD locate. This allows for non-case-sensitive queries and for basename-only queries as I requested.

Martino
  • 111
  • mdfind will only work if you have the Spotlight service enabled (on by default, or enabled manually with sudo mdutil -i on / -E); if it's disabled (i.e. sudo mdutil -a -i off) then mdfind won't work – ccpizza Feb 15 '24 at 12:20