If you use some Linux distribution, there should be - but only for packages in distribution, for all stuff installed via some other way (like in /opt
or /usr/local
) you would still need to use your original method.
for example, on Debian-based distro, we would first find in which package is our shared library:
# dpkg -S /usr/lib/libgs.so.9.05 libgs9: /usr/lib/libgs.so.9.05
and then find all packages which use that library (and keep copy in file packages.txt):
# dpkg-query -W -f='$ $\n' | grep -w libgs9 | awk '' | tee packages.txt ghostscript gimp libgs9 libgs9-common
If you need to know exact binaries which use the libraries, you could parse that output some more:
# while read pkg; do dpkg -L $pkg | xargs -i sh -c 'test -f {} -a -x {} && ldd {} | fgrep -H --label={} libgs.so.9'; done < packages.txt /usr/bin/gs: libgs.so.9 => /usr/lib/libgs.so.9 (0x00007fefe5611000) /usr/bin/ghostscript: libgs.so.9 => /usr/lib/libgs.so.9 (0x00007fbad0d71000) /usr/lib/gimp/2.0/plug-ins/file-ps: libgs.so.9 => /usr/lib/libgs.so.9 (0x00007f75f0a51000)