Libraries needed for binary



You need to move a binary, but are unsure of it's dependencies? This script uses ldd and rpm to list the RPMs and standalone libraries needed for a dynamically linked executable.

#!/bin/bash
# myneeds.sh [FILE]
FILE=${1:?"error: no file argument"}

#parse the library listing
LIBS=$(ldd $FILE | sed -r 's:[^/]*(/.*)\ .*:\1:' | grep -e '^/' | sort | uniq)

# query the rpm database
rpm -qf $LIBS | sort | uniq -c
exit $?

Examples

bash$ ./myneeds.sh /usr/bin/mutt
1 cyrus-sasl-lib-2.1.22-8.fc8.x86_64
1 db4-4.6.21-1.fc8.x86_64
1 e2fsprogs-libs-1.40.4-2.fc8.x86_64
7 glibc-2.7-2.x86_64
1 gnutls-1.6.3-2.fc8.x86_64
1 keyutils-libs-1.2-2.fc6.x86_64
4 krb5-libs-1.6.2-14.fc8.x86_64
1 libgcrypt-1.2.4-6.x86_64
1 libgpg-error-1.5-6.x86_64
1 libidn-0.6.14-4.x86_64
1 libselinux-2.0.43-1.fc8.x86_64
2 ncurses-5.6-12.20070812.fc8.x86_64
1 zlib-1.2.3-14.fc8.x86_64
bash$ ./myneeds.sh /opt/apache2/bin/httpd
1 e2fsprogs-libs-1.40.4-2.fc8.x86_64
1 expat-2.0.1-2.x86_64
1 file /opt/apache2/lib/libapr-1.so.0 is not owned by any package
1 file /opt/apache2/lib/libaprutil-1.so.0 is not owned by any package
7 glibc-2.7-2.x86_64
1 sqlite-3.4.2-3.fc8.x86_64