How to find out a file belongs to which package in Mac OS X?
Solution 1
It's a little late, but perhaps it will be of help to others.
You can use the pkgutil
command.
For example, if you want to know what package the "less" command belongs to run:
pkgutil --file-info /usr/bin/less
Which will output something like:
volume: /
path: /usr/bin/less
pkgid: com.apple.pkg.BaseSystemBinaries
pkg-version: 10.7.0.1.1.1309742044
install-time: 1310407891
uid: 0
gid: 0
mode: 755
To list all files contained in a package, com.apple.pkg.BaseSystemBinaries
in our example, run:
pkgutil --files com.apple.pkg.BaseSystemBinaries
I know this tool has been present since OS X 10.6.
Solution 2
This is not really possible since there's no standardized package management.
Unless you configured MacPorts or Homebrew differently, you'll always find their executables in a location that nobody else uses. Since MacPorts and Homebrew do not run under a separate user account, the files they create will always be owned by your user or root
.
What's left is that you can only try to guess based on the executable location. Here are some rules:
MacPorts uses
/opt/local/bin
and/opt/local/sbin
for executables, everything prefixed under/opt/local
.Homebrew uses
/usr/local/bin
for executables, everything else under/usr/local/
.Other applications should create their own directories somewhere under
/usr
, e.g./usr/local/git/bin
for the Git OS X installer or/usr/X11/bin
for X11.Some system frameworks symlink to
/usr/bin
, e.g.rake
points to/System/Library/Frameworks/Ruby.framework
No application should ever use
/bin
or/sbin
. No third party application (i.e. anything not an OS X framework) should use/usr/bin
either.
Solution 3
To collect them in one place for the two other package managers on OSX:
For MacPorts (as mentioned by Neil in comments above):
port provides /opt/local/bin/progname
For Brew it's not so simple but one can usually find the package using:
ls -la /usr/local/bin/progname
Which should show a softlink that contains the package name, or else one can use other suggestions from one of these questions.
Related videos on Youtube
hanxue
I am currently a full-stack software engineer based in Beijing, as well as traditional internal martial artist.
Updated on September 18, 2022Comments
-
hanxue almost 2 years
Is there a way to find out which Application / package owns or creates a specific file? For example, in Linux these commands will show the package owner
apt-file /bin/progname rpm -qf /bin/progname yum whatprovides /bin/progname
In OS X, a file could be part of a native OS X application, or installed by Macports or Homebrew. These are completely different environments. Are there commands for each environment to check which application / package owns a specific file?
-
Neil Mayhew about 9 yearsIt's not true there's no standardized package management. Mac OS X installs almost all software from packages (using the Installer) and keepsa record. See answer from @bhavin.
-
slhck about 9 yearsYou're right. I was more talking about the programs which might not use standard packages. Didn't know much about pkgutil when I wrote this answer.
-
Neil Mayhew about 9 yearsI didn't know about
pkgutil
either, and it sounds pretty handy. -
Neil Mayhew about 9 yearsWith MacPorts, you can find out which port owns a particular file using
port provides FILE
-
juandesant over 8 yearsThis should be marked as the right answer. You can even use it with GUI applications. Try
pkgutil --file-info /Applications/TextEdit.app
, and you'll get that it belongs to com.apple.pkg.Essentials, but will also tell you which updaters have been applied to it (in my case, com.apple.pkg.update.os.10.10.2.14C109.patch, com.apple.pkg.update.os.10.10.3.14D131.delta, com.apple.pkg.update.os.10.9.2.13C64.combo). -
0 _ about 3 yearsRelevant: stackoverflow.com/a/25460320/1959808
-
vlad-ardelean about 3 yearsdoesn't work for me on Big Sur 11.4.
pkgutil --file-info less
just tells mevolume: /
andpath: less
. For other packages, it also just displays the volume and path info, but I can't get the package id, and can't get to the files