Determine which executables link to a specific shared library on Linux
How can I list all executables on my Red Hat Linux system which link to libssl? I can get close with:
find / -t开发者_如何转开发ype f -perm /a+x -exec ldd {} \; | grep libssl
ldd shows me which libraries the executable links with, but the line that contains the library name does not also show the filename, so although I get a lot of matches with grep, I can't figure out how to back out the name of the executable from which the match occured. Any help would be greatly appreciated.
find / -type f -perm /a+x -print0 |
while read -d $'\0' FILE; do
ldd "$FILE" | grep -q libssl && echo "$FILE"
done
I'm not sure, but maybe sudo lsof |grep libssl.so
find /usr/bin/ -type f -perm /a+x | while read i; do match=`ldd $i | grep libssl`; [[ $match ]] && echo $i; done
Instead of using -exec, pipe to a while loop and check a match before you echo the file name. Optionally, you could add "ldd $i" to the check on match using either () or a real if/then/fi block.
find / -type f -perm /a+x -xdev | while read filename ; do
if ldd "$filename" | grep -q "libssl" ; then
echo "$filename"
fi
done
The -xdev
makes find stay on the same filesystem (i.e. it won't dive into /proc or /sys). Note: if constructed this on Mac OS X, the -perm of yours doesn't work here so I don't know whether it's correct. And instead of ldd
I've used otool -L
but the result should be the same.
精彩评论