locate command and Finder do not find many files

The locate command doesn't work properly anymore under Big Sur I have tried to update the locate database but I get some errors:


sudo /usr/libexec/locate.updatedb 
Password:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied


After these errors the command completes. locate will find some files but not others. The files I'm looking for my user definitely has access to and for sure root does. There seems to be no rhyme or reason to what files it finds and what it doesn't.


An example of files that locate won't find are files I know that exist in subdirectories of


/Users/username/Library/Application Support/


Mac Finder also doesn't find these files no matter how long I let it search "This Mac" or "Macintosh HD"


This all used to work under Catalina.


How can I fix my locate and Finder search?



MacBook Pro with Touch Bar

Posted on Dec 25, 2020 6:01 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 25, 2020 7:00 AM

The operating system (which has the privileges to do so) will update the locate database either daily or weekly depending upon how the operating system is configured by Apple. You cannot update the database because it is now located on a read-only, signed system partition.


You do have a more effective method of discovering files than locate. It is mdfind, which has no issue quickly discovering files. For instance, if I want to find the Firefox installs.ini file in ~/Library/Application Support/Firefox:


mdfind installs.ini


You can send direct feedback to the Apple macOS product team about the locate and locate.updated utilities.

11 replies
Question marked as Top-ranking reply

Dec 25, 2020 7:00 AM in response to brsm1990

The operating system (which has the privileges to do so) will update the locate database either daily or weekly depending upon how the operating system is configured by Apple. You cannot update the database because it is now located on a read-only, signed system partition.


You do have a more effective method of discovering files than locate. It is mdfind, which has no issue quickly discovering files. For instance, if I want to find the Firefox installs.ini file in ~/Library/Application Support/Firefox:


mdfind installs.ini


You can send direct feedback to the Apple macOS product team about the locate and locate.updated utilities.

Dec 26, 2020 6:22 AM in response to brsm1990

I found that if I go to my home directory, then View > Show View Options then check "Show Library Folder" then open the Library folder in finder and search, I can find files that are in Library and subdirectories of it. But if I go back and search "Macintosh HD", "This Mac", even my home folder (of which Library is a subdirectory) it doesn't find any of those files.

It has always been like this. Spotlight does not show "system" files by default. Very few people want to find config files or any other useless dreck when they are searching for content in files they've created.

As you found, you can search them if you start from within the Library. You can also add the "system files are included" criteria in a Finder search to get it to return those types of files.

Dec 25, 2020 7:22 AM in response to brsm1990

If you switched your default shell to Zsh, it is not reading the Bash dot files to get your PATH. You need a ~/.zshrc file in your home directory that Zsh will read when the Terminal is opened. You must create that file and enter the following content:


export PATH=".:$HOME:/usr/local/bin:$PATH
PS1="%m %~ %% "
# enable vi/vim keystrokes for inline editing of Terminal commands
bindkey -v



To make that information available in the current Terminal session:


source ~/.zshrc


At minimum, the operating system will update the locate database daily, probably first thing in the morning, or when you power on the Mac, so it is a scheduled, not a random event.


In Finder Preferences, set the following:

  1. General
    1. New Finder windows show [ your user name ]
  2. Advanced
    1. When performing a search: [ Search the Current folder ]


Take advantage of the Spotlight keywords that you can use to narrow your search results whether in the Finder window's search window, or from the Spotlight dialog itself.


Apple is always about change, not position, and you can expect the former, no matter how inane it may seem. Take the current Finder open and save panels for example. Who inside Apple would look at those and actually believe that it was normal?

Dec 25, 2020 7:05 AM in response to VikingOSX

Well that sounds just terrible. There is no way to update the locate db except to just wait for it to update at random?


For some reason mdfind (/usr/bin/mdfind) is not in my path. If I type the full path to /usr/bin/mdfind it works great. Shouldn't this be in my path? Can I fix that?


Any idea why the search function in Finder doesn't work properly?


I can't believe Big Sur requires users to learn a new method to do something as elementary as "find a file".

Dec 25, 2020 7:40 AM in response to VikingOSX

Thanks. I guess I forgot changing to a default of zsh.


"# set path for python 3.7
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH"


I had this in .bash_profile - do you know how to adapt it to have that too. Is it this or something else?


export PATH=".:$HOME:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH


I understand what you're saying there about the finder preferences but what about when I want to search "This Mac" or "Macintosh HD" for a file that I don't know the location of? I find that if it's located in ~/Library (or a subdirectory of Library) it won't find it if I search "Macintosh HD" or "This Mac", it only finds it if I search Library. I don't know how many other folders (if any) that might be the case for. I often need to find a file I don't know the location of. I use a lot of different software on a lot of different operating systems and I am always looking for "where does Mac store that file" - often times a configuration which is often in ~/Library, but not always. Is there any way to actually search my whole Mac for a file I don't know the location of besides mdfind? Is finder just useless for this now? And if so why do they gave you an option "Search This Mac" or "Search Macintosh HD" when they know full well they are not actually going to search the whole thing, this is super misleading and frustrating. I just discovered this today because I was searching for one of those configuration files I know must exist but not where. I might have never figured this out except for dumb luck trial and error.


Also just noticed mdfind will not find files that start with . - is that a known thing too?

Dec 26, 2020 5:14 AM in response to VikingOSX

So should my .zshrc look like this?



export PATH=".:$HOME:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH
PS1="%m %~ %% "
# enable vi/vim keystrokes for inline editing of Terminal commands 
bindkey -v


What is the PS1="%m %~ %% " for?


My output from:

ls /usr/local/bin/*3

is:

/usr/local/bin/2to3	/usr/local/bin/pip3	/usr/local/bin/python3
/usr/local/bin/idle3	/usr/local/bin/pydoc3	/usr/local/bin/wheel3



I am not sure what you mean by this:


VikingOSX wrote:

I think if you are looking for a file in your ~/Library, that you may be more successful using just the filename in Spotlight, rather than name:filename. Spotlight would not find that Firefox installs.ini file until I just specified the filename without any keyword.


I should get different results if I search like this:



As opposed to if I search it like this:



Whether I select the suggestion of "Name matches:" or ignore that and just type the file name nothing is found in finder if I select "This Mac" or "Macintosh HD" unless I specifically select Library which makes no sense to me. Why does it say it's searching the whole hard drive or the whole make if it doesn't? What other folders does it exclude without telling me or me asking it to exclude besides Library, if any?


There are lots of reasons I don't want to use spotlight search but mainly when I'm doing these types of searches I want to see the file size, date, location, right click it, etc. and I can't do any of that in the list I get from spotlight.


I also noticed that spotlight wants to open this with Brave when the file association I have for .ini says it should be opened with a text editor. Why does it do that? Is there any fix?



Thanks for your help.

Dec 26, 2020 5:33 AM in response to brsm1990

The PS1 is your Zsh shell prompt. The tilde ~ appears when you are in your home directory, and changes to your current folder path (e.g. ~/Desktop) when you change directory. This is what I use.


The PATH is fine as you have shown it.


In the Finder, right-click on that Brave installs.ini file, and press option+command+i. This will open a Get Info panel mid-screen (instead of beneath a browser window), where you can visit the Open With section, and change the default opening application to your programmer's editor name. If you want all files ending in .ini to use this editor, then you would click thru the Change All… button. If only the Brave installs.ini, then ignore the Change All… button. I would not recommend TextEdit unless you are absolutely certain that it will open and save that installs.ini as a plain text, and not RTF formatted file.

Dec 26, 2020 6:19 AM in response to VikingOSX

Thanks for clarifying.


There is actually no Brave installs.ini. There are only two:


/Users/user/Library/Thunderbird/installs.ini

/Users/user/Library/Application Support/Firefox/installs.ini


When I find them in finder and do as you said they are already associated as they should be. Just to be safe I associated them to something else and then associated them back and did "Change All"


It still shows as Brave in spotlight:




Also unclear why Spotlight only finds one of the two files. It's not like that with other files.


Is there any known answer as to why Finder won't find files in ~/Library when "This Mac" or "Macintosh HD" is selected and/or what folders (if any) are also excluded unless they are specifically selected? Any fix?

Dec 25, 2020 7:01 AM in response to brsm1990

I found that if I go to my home directory, then View > Show View Options then check "Show Library Folder" then open the Library folder in finder and search, I can find files that are in Library and subdirectories of it. But if I go back and search "Macintosh HD", "This Mac", even my home folder (of which Library is a subdirectory) it doesn't find any of those files. Is this another Big Sur bug like the inability to snooze your calendar notifications? This is really awful. Why can't I do a basic thing like search for files and why is the locate command suddenly totally broken?

Dec 25, 2020 8:51 AM in response to brsm1990

On face value, the PATH statement for a Python.org installed Python3.6.* distribution is:


export PATH=".:$HOME:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:$PATH


The Python.org installer adds a separate PATH statement in the ~/.bash_profile that appends your PATH to it, but it does not insert that information into the Zsh ~/.zshrc file. Its interesting that the Python.org install symlinks the important Python3 related binaries from that library path into /usr/local/bin. You can confirm this with:


ls /usr/local/bin/*3


Python 3.6.* is pretty old, and the 3.9.1 distribution is current. That is what I have installed on my M1 mini using the Python.org universal2 distribution. There is a 3.9.1 installer for just Intel available too.


I think if you are looking for a file in your ~/Library, that you may be more successful using just the filename in Spotlight, rather than name:filename. Spotlight would not find that Firefox installs.ini file until I just specified the filename without any keyword.

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 and Finder do not find many files

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