How to get the list of installed library packages only?

I want to get the list of installed library packages only from terminal.

Is there any command for that?


/sbin/ldconfig -p

The -v option will show the libraries version.

Result:

267 libs found in cache `/etc/ld.so.cache'
        libz.so.1 (libc6) => /usr/lib/libz.so.1
        libz.so (libc6) => /usr/lib/libz.so
        libxslt.so.1 (libc6) => /usr/lib/libxslt.so.1
        libxml2.so.2 (libc6) => /usr/lib/libxml2.so.2
        libxcb.so.1 (libc6) => /usr/lib/libxcb.so.1
        libxcb-xlib.so.0 (libc6) => /usr/lib/libxcb-xlib.so.0
        libwrap.so.0 (libc6) => /lib/libwrap.so.0
        libvolume_id.so.0 (libc6) => /lib/libvolume_id.so.0
        libuuid.so.1 (libc6) => /lib/libuuid.so.1
        libutil.so.1 (libc6, hwcap: 0x8008000000008000, OS ABI: Linux 2.6.8) => /lib/tls/i686/cmov/libutil.so.1
        libutil.so.1 (libc6, OS ABI: Linux 2.6.8) => /lib/libutil.so.1
        libutil.so (libc6, OS ABI: Linux 2.6.8) => /usr/lib/libutil.so
        libusb-0.1.so.4 (libc6) => /lib/libusb-0.1.so.4
        libusb-0.1.so.4 (libc6) => /usr/lib/libusb-0.1.so.4
        libulockmgr.so.1 (libc6) => /lib/libulockmgr.so.1
        libt1x.so.5 (libc6) => /usr/lib/libt1x.so.5
        libt1.so.5 (libc6) => /usr/lib/libt1.so.5
        libtiff.so.4 (libc6) => /usr/lib/libtiff.so.4
        libticw.so.5 (libc6) => /lib/libticw.so.5

If you want to turn that list into a list of packages, you can do something like this:

dpkg -S $(/sbin/ldconfig -p | awk 'NR>1 { print $NF }')

And you can further massage that to cut out errors, unneeded components and duplicates:

$ dpkg -S $(/sbin/ldconfig -p | awk 'NR>1 { print $NF }') 2>/dev/null | sed 's/\: .*$//' | sort -u
akregator
ark
binutils
calligra-libs
comerr-dev
compiz-core
dolphin
e2fslibs:amd64
freeglut3:amd64
gettext
...

I'm not sure there's a guaranteed way to know from a package name that a package is a "library" (if that's even a solid definition in itself) but you can find installed packages that start and end with lib fairly easily:

dpkg -l | awk '($1 == "ii") && ($2 ~ /^lib|lib$/) { print $2 }'

Some packages contain "lib" that aren't libraries. You'll probably need to exclude librarian and libreoffice from those:

dpkg -l | awk '($1 == "ii") && ($2 ~ /^lib|lib$/) && ($2 !~ /^(libreoffice|librarian)/) { print $2 }'

This is still going to miss out a dearth of python-... libraries.


And aptitude came to the rescue:

aptitude search '?and(?section(libs), ~i)'

It reads: looks for packages that contains libs in their ?section and that are installed (~i).

You can use this to look for just all libraries in your repository:

aptitude search '?section(libs)'

This method obviously need of aptitude.