How to get Brew formula from the filename of installed binary? I often use dpkg -S &lt;file&gt; on Debian to get the package name that installed &lt;file&gt;.

However, using brew I cannot find this option anywhere?

How can I obtain the Brew formula that installed a given binary?
The brew whence external command takes an executable and looks up the Homebrew formula from where the executable comes.

Installing

To install the brew whence command, run:

$ brew tap claui/whence


Running

To run brew whence, pass it an executable:

$ brew whence python3



Executable                Comes from    
==========                ==========    
/usr/local/bin/python3    → python 3.7.7



Or pass it several executables at once:

$ brew whence 7z git-shell lzgrep



Executable                  Comes from
==========                  ==========
/usr/local/bin/7z           → p7zip 16.02_2
/usr/local/bin/git-shell    → git 2.26.0
/usr/local/bin/lzgrep       → xz 5.2.5



More information

For more information and examples, run brew help whence:

$ brew help whence


Full disclosure

Full disclosure: I wrote this command.
It is not part of Homebrew proper but you can inspect the code yourself.