Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a utility that would behave in the same way as which, but to look up shared libraries (*.so) in the directories defined in $LD_LIBRARY_PATH?

share|improve this question
up vote 4 down vote accepted

If you have an executable and you want to see where it's picking up libraries, run

ldd /path/to/executable

This will account for libraries on the default search path as well as libraries in this executable's rpath if any.

On Linux, paths to system libraries are cached for efficiency. /sbin/ldconfig -p displays the contents of the cache (it's stored in /etc/ld.so.cache). Here's a script that shows the location(s) of a library:

if [ -n "$LD_LIBRARY_PATH" ]; then
  set -f
  for d in $LD_LIBRARY_PATH; do
    if [ -e "$d/$1" ]; then echo "$1"; fi
/sbin/ldconfig -p |
awk -v needle="$1" '$1 == needle {sub(/.* => /, ""); print}'
share|improve this answer

If your libraries are properly cached you should be abled to find it via:

ldconfig -p|grep "yourlibrary"

If you search for a library that came with your distribution you could use the distribution means of searching for files within packages.

  • zypper wp "*/library.so" (SLES and OpenSuSE)
  • yum provides "*/library.so" (RedHat and its clones)

This will also output rpms that are not installed, but are part of your active installation sources.

share|improve this answer

If you are looking for a utility that will work like gcc's -lLIBNAME flag, which looks for a file called libLIBNAME.so then you could probably use a little script that does something like this:

for libdir in ${ldpath//:/ }; do
        (test -f "$libdir/lib${1}.so" && echo "$_") && notfound=0
[ "$notfound" -eq 0 ]
share|improve this answer
Thanks for the script but I'm really wondering if there's a "standard" utility for this. – rahmu Oct 6 '11 at 20:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.