I have large number of shared libraries like this:

libexpat.so.1.6.7                        libqquicklayoutsplugin.so        libstdc++.so.6.0.24
libexportlib.so.1.0.0                    libqsvg.so                       libsystemd.so.0.19.0
libfontconfig.so.1.10.1                  libQt53DAnimation.so.5.11.3      libwidgetsplugin.so
libfreetype.so.6.16.0                    libQt53DCore.so.5.11.3           libwindowplugin.so
libgcc_s.so.1                            libQt53DExtras.so.5.11.3         libX11.so.6.3.0
libgcrypt.so.20.2.2                      libQt53DInput.so.5.11.3          libX11-xcb.so.1.0.0

I'm trying to loop over all my shared libraries and create sym-links by dropping their version number (if they have any version number). For example:

libgcrypt.so.20.2   -> libgcrypt.so.20.2.2
libgcrypt.so.20     -> libgcrypt.so.20.2.2
libgcrypt.so        -> libgcrypt.so.20.2.2

So far I have tried to find all shared libraries with version number with:

find . -name '*.so.*'

But I cannot figure out how to use awk and ln -s commands:

find . -name '*.so.*' -exec #awk and ln -s commands goes here# \;

Can anybody give me a hint?


This really seems to be the job of something else (ldconfig?), but:

find . -name '*.so.*' -exec sh -c '
for so; do
  while [ "${target##*.}" != "$target" ]; do
    echo ln -s "$so" "$target"
done' _ {} +

The shell command loops over arguments (the filenames), and for each filename, strips off extensions to get link targets (until the target has no extension, after the .so gets stripped off). Remove the echo to actually make the links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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