TransWikia.com

`locate` in linux vs osx

Unix & Linux Asked by Bzazz on March 7, 2021

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?

2 Answers

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.

Answered by Bzazz on March 7, 2021

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

Answered by kasa on March 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP