Locate command not working

The locate command is not finding all the files on my iMac even when the database is updated.

For example, it will return the Application and contents but not the Library Preferences or other files under the same name. It used to return every file there was. Was there something changed?

iMac 21.5″ 4K, macOS 11.6

Posted on Oct 23, 2021 7:20 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 24, 2021 7:28 AM

danuke wrote:

Evidently I was not clear. This is a Unix Terminal Command Line. The Community used to have Unix as a topic area, but I did not see it.


I can only assume your current shell is zsh...(?) unless you sate otherwise.


You can see your options from the Terminal.app copy & paste:

man locate | more



see the note on Bugs:


The locate program may fail to list some files that are present, or may list files that have been removed from the system. This is because locate only reports files that are present in the database, which is typically only regenerated once a week by the /System/Library/LaunchDaemons/com.apple.locate.plist job.

Use find(1) to locate files that are of a more transitory nature.


ref:

man find | more



You will have to give more specific examples if you want a more specific answer..




Terminal User Guide for Mac - Apple Support



Similar questions

12 replies
Question marked as Top-ranking reply

Oct 24, 2021 7:28 AM in response to danuke

danuke wrote:

Evidently I was not clear. This is a Unix Terminal Command Line. The Community used to have Unix as a topic area, but I did not see it.


I can only assume your current shell is zsh...(?) unless you sate otherwise.


You can see your options from the Terminal.app copy & paste:

man locate | more



see the note on Bugs:


The locate program may fail to list some files that are present, or may list files that have been removed from the system. This is because locate only reports files that are present in the database, which is typically only regenerated once a week by the /System/Library/LaunchDaemons/com.apple.locate.plist job.

Use find(1) to locate files that are of a more transitory nature.


ref:

man find | more



You will have to give more specific examples if you want a more specific answer..




Terminal User Guide for Mac - Apple Support



Oct 25, 2021 10:54 AM in response to danuke

It would help if you could post specific examples of what's not working. That might help identify problems with locate, with your locate.db, or some other error.


As is stands, I can't get locate to fail on locating files in the directories you mention:


% locate com.apple.timezone.auto.plist
/Library/Preferences/com.apple.timezone.auto.plist


or:


% locate com.apple | grep ^/Library/Preferences/
/Library/Preferences/Audio/com.apple.audio.DeviceSettings.plist
/Library/Preferences/Audio/com.apple.audio.SystemSettings.plist
/Library/Preferences/Logging/Subsystems/com.apple.WebInspector.plist
/Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist
/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
/Library/Preferences/SystemConfiguration/com.apple.accounts.exists.plist
/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist
... plus many more


The other caveat that comes to mind is permissions. As per man locate:


The locate database is typically built by user ``nobody'' and the locate.updatedb(8) utility skips directories

which are not readable for user ``nobody'', group ``nobody'', or world. For example, if your HOME directory is

not world-readable, none of your files are in the database.


So maybe the files you're looking for are in directories that are not readable to the daemon.

Oct 25, 2021 1:12 PM in response to Camelot

Camelot wrote:

As is stands, I can't get locate to fail on locating files in the directories you mention:

% locate com.apple.timezone.auto.plist
/Library/Preferences/com.apple.timezone.auto.plist

I found something interesting in the OP's other thread: unix locate command line working properly - Apple Community


I suggested using "mdfind" instead of "locate". Unfortunately, any "Preferences" folder seems to be excluded from Spotlight at a very low level. I was unable to change this. I was also unable to find a list of any similarly excluded folders by any method other than trial and error. For example, "/tmp" appears to be excluded too. But lots of other places, such as "Application Support" and deep inside app containers, are returned from "mdfind".


But it really annoys me to see certain things mysteriously excluded with no documentation. Furthermore, the is purposeful work on Apple's part to hide this fact. For example, you can search for file names in a Preferences folder but only using the Finder Spotlight UI. But that isn't even a true Spotlight search. It will only find files by name, not content. And you have to manually specify the folder, effectively defeating the purpose of "search".

Oct 25, 2021 1:00 PM in response to Camelot

Evidently sometime in the near past, the user library preferences did indeed get changed by Apple. Thank you for reading the locate man closer that I did. I went in and changed some of the read preferences, updated the database again the the locate search returned results similar to what it used to.

So this reply actually SOLVED IT.

Oct 23, 2021 7:41 AM in response to danuke

danuke wrote:

The locate command is not finding all the files on my iMac even when the database is updated.
For example, it will return the Application and contents but not the Library Preferences or other files under the same name. It used to return every file there was. Was there something changed?


What exactly is the "locate command" ...?

If this is Spotlight Search (Command Spacebar) ...


Verify your Spotlight preferences include all the locations you want included:

>System Preferences>Spotlight>Preferences


You can always rebuild the index: Rebuild the Spotlight index on your Mac - Apple Support


Oct 24, 2021 8:17 AM in response to leroydouglas

I am aware of that. As I have said, I have updated the database. I also know that the files and directories that I was looking for are were indeed there after the locate search failed to find them. Further the find command is far less efficient than the locate command line.

Seeing as how I referred to Big Sur, you can assume correctly. How specific of an example do you want, an entire listing of the locate search results? I thought that I was specific:

I stated:

Application & contients

but not any Library Directory, ok more specific then"

how about the common and usual suspects such as"

Library > Application Support > Application or Vendor name

Library > Preferences > com. Application or Vendor name


all these used to be returned under a locate search which I have been using for years; but not now.

I perform a database update before I issue a locate command line search.

Oct 24, 2021 9:19 AM in response to danuke

danuke wrote:

Further the find command is far less efficient than the locate command line.

Seeing as how I referred to Big Sur, you can assume correctly. How specific of an example do you want, an entire listing of the locate search results?

all these used to be returned under a locate search which I have been using for years; but not now.
I perform a database update before I issue a locate command line search.

Seeing as how you did not actually know what this is would best be answered by someone else?


you do pose the question "Was there something changed?"...

are we comparing shells ie bash to zsh behavior— or —you have been using zsh since 2019 without issue and now something has changed? So yes it is still a bit unclear.


I'll try moving this thread over to Technologies for more eyes on your issue ...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Locate command not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.