unix locate command line working properly

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

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?


Also, did there not used to be a Unix topic forum or such?


iMac 21.5″ 4K, macOS 11.6

Posted on Oct 24, 2021 8:44 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 25, 2021 11:32 AM

danuke wrote:

Yes, I did try the Mac OS Tech. Forum, but when the reply was that they had never heard of the "locate command", I pretty much knew that I was in the wrong place.

I wouldn't read too much into that. While I know about the "locate" command, I don't think I've ever used it, and I first used UNIX in 1990 I think.

Also, as mentioned, the Terminal / Unix Topic area seems to have gone away.

I don't think any such topic area ever existed, at least not since I've been here circa 2007.

On top of that, Apple Support has refused to discuss anything to do with the terminal for years, despite all their touting how wonderful have it for users was.

Apple Support is for consumer-oriented questions. They won't know anything about Terminal.

Spotlight has NEVER been able to find all those files. Not no way, not no how.

I'm talking about Spotlight in terms of the underlying service and database, not the UI control in the Finder. The "mdfind" command will definitely find all those files. If anything, you will have to tune it to reduce the number of hits that it returns because it searches both file names and contents. By default, the UI control will hide any system locations, which are usually the ones you want. It is possible to change that. But if you are looking for a Terminal command, mdfind is definitely the one you want.

Similar questions

7 replies
Question marked as Top-ranking reply

Oct 25, 2021 11:32 AM in response to danuke

danuke wrote:

Yes, I did try the Mac OS Tech. Forum, but when the reply was that they had never heard of the "locate command", I pretty much knew that I was in the wrong place.

I wouldn't read too much into that. While I know about the "locate" command, I don't think I've ever used it, and I first used UNIX in 1990 I think.

Also, as mentioned, the Terminal / Unix Topic area seems to have gone away.

I don't think any such topic area ever existed, at least not since I've been here circa 2007.

On top of that, Apple Support has refused to discuss anything to do with the terminal for years, despite all their touting how wonderful have it for users was.

Apple Support is for consumer-oriented questions. They won't know anything about Terminal.

Spotlight has NEVER been able to find all those files. Not no way, not no how.

I'm talking about Spotlight in terms of the underlying service and database, not the UI control in the Finder. The "mdfind" command will definitely find all those files. If anything, you will have to tune it to reduce the number of hits that it returns because it searches both file names and contents. By default, the UI control will hide any system locations, which are usually the ones you want. It is possible to change that. But if you are looking for a Terminal command, mdfind is definitely the one you want.

Oct 25, 2021 9:03 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 immediately before issuing the command.
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?

I am unaware of the locate command ever behaving the way you describe. I can't imagine it would ever have a database of all files on the Mac. That would be just huge and quite intensive to keep updated. Apparently, it isn't even turned on by default.

Also, did there not used to be a Unix topic forum or such?

There is the Mac OS X Technologies forum, which you have already tried, but that is mostly AppleScript.


I suggest using the "mdfind" command instead of locate. It uses Spotlight so it should always be updated.

Oct 25, 2021 12:06 PM in response to etresoft

Howdy again,

There seems to be several things going on here.

Yes there did indeed used to be a Unix/Terminal Topic site here. I had piddled with Unix with the first Mac, but did not get serious about it, I had three nuclear power plants to start up and was working 20/7s in systems operations.


I have not used locate to search files for a while, and it appears that since then, Apple changed the user library permissions in that they removed world read access. Without that, the locate database did not find those associated files in say Application Support or Preferences. I changed that and and locate now returns the expected files, but I am also looking into the mdfind as you recommend.

Oct 25, 2021 1:02 PM in response to danuke

danuke wrote:

I changed that and and locate now returns the expected files, but I am also looking into the mdfind as you recommend.

I've been looking more into mdfind too and I'm no longer as confident about it. It is definitely excluding "Preferences" folders in some way. More importantly, I have also been unable to find out what other folders, if any, are similarly excluded. Except for "Preferences" folders, mdfind seems to return result from all of the disk, even deep within places that would never be returned in the Finder.


As far as I can tell, this folder, and possibly others (such as /tmp), have been purposefully excluded from Spotlight. I tried to manually import them without success. Curiously, Finder is able to locate files in these folders, but only if you manually select the folder. Even then, it is not a true Spotlight search as it is only searching the file name.


I'm annoyed.

Oct 25, 2021 10:02 AM in response to etresoft

I appreciate your reply,


Yes, I did try the Mac OS Tech. Forum, but when the reply was that they had never heard of the "locate command", I pretty much knew that I was in the wrong place. Also, as mentioned, the Terminal / Unix Topic area seems to have gone away.

On top of that, Apple Support has refused to discuss anything to do with the terminal for years, despite all their touting how wonderful have it for users was.

The database has always been there. Way back it when, if memory serves, one of the biggest delays when first setting up a Mac was the time it took for the database to initialize. Then it would auto update or one could use a simple command line like periodic, or weekly to do various "level" updates. Now the database update command is more complex and yes one has to 'turn it on'. But I could find every file associated with a name or partial name on my computer. Manual updating is necessary, because if one deletes a file for example, the locate command will continue to show it. When a program is acting up or I want to delete every file associated with a program, locate has always been the way to go about it because there are associated files lurking about everywhere.

Spotlight has NEVER been able to find all those files. Not no way, not no how.

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.

unix locate command line working properly

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