Created
April 19, 2024 16:58
-
-
Save ernstki/25d4492748b696ae42956cb001262c1b to your computer and use it in GitHub Desktop.
Wrapper script for macOS's `pkgutil` to list full pathnames of files in all packages, or packages matching a pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
pkgutil --packages \ | |
| if [[ "$1" ]]; then grep -i "$1"; else cat; fi \ | |
| perl -nE ' | |
#line 5 "pkgutil-list-files" | |
chomp; | |
print STDERR "# scanning $_…\n"; | |
$location = `pkgutil --pkg-info $_`; | |
$location =~ s/.*location: (.*?)\n.*/$1/s; | |
print STDERR "# location: $1\n"; | |
print STDERR "# running \`pkgutil --files $_\`"; | |
open $fh, "-|", "pkgutil --files $_"; | |
while ($path = <$fh>) { | |
$pkgfile = $location ? "/$location/$path" : "/$path"; | |
# `if -f $pkgfile` doesn’t work here for some reason :( | |
print "$_\t$pkgfile"; | |
} | |
close $fh; | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first column of the output (tab-separated) is the package name. If you are brave enough to
xargs rm
the output of this command, then pipe throughcut -f2
first to get the second column.Remove or comment out
print STDERR
statements if it's too chatty for you, or simplypkgutil-list-files 2>/dev/null
to suppress them for a single run.See also: https://stackoverflow.com/questions/25925752/uninstall-packages-in-mac-os-x