0

I have a directory full of libraries (*.so.0.*), and I want to use find to create a symbolic link to each file, named *.so.0.

Here is a (non working) try:

find $HOME/.local/lib64/ -name "lib*.so.0.*" -execdir ln -s {} $(echo {} | cut -d . -f 1-4) \;

But I cannot find why it doesn't work.

I tried with only one library, using ln -s ./libfoo.so.0.12.0. $(echo ./libfoo.so.0.12.0. | cut -d . -f 1-4), the result being ./libfoo.so.0.

  • Have you considered simply linking to the directory, as opposed to the files themselves? Depending on whether this suffices for your purposes, it removes the need for the use of find and you can simply link the directory. – tniles May 10 '16 at 17:35
  • 2
    Why don't you just cd to that dir and for f in lib*.so.0.*; do echo ln -s "$f" "${f%%.*}.so.0"; done (remove the echo if OK) ? – don_crissti May 10 '16 at 17:37
  • - @tniles09 I want to execute a program that need the library named like this, $HOME/.local/lib64/ being inside LD_LIBRARY_PATH. - @don_crissti It seems to work, but I will probably have to do the command for multiple directories, as all these lib aren't directly inside $HOME/.local/lib64/ (some being in sub-directories). Moreover, I'll soon have to evolve this command in order to make it works for $HOME/.local/lib64/ and $HOME/.local/lib32/. - @drg ln: failed to create symbolic link '$(echo ./libfoo.so.0.12.0. | cut -d . -f 1-4)': No such file or directory – Dremor May 10 '16 at 17:50
  • 1
    I've found my answer here (I did not find it during my previous search) : stackoverflow.com/questions/21825393/… Worked with find $HOME/.local/lib64/ -name 'lib*.so.0.*' -execdir bash -c 'ln -s {} $(echo {} | cut -d . -f 1-4)' \; Thank for your help @don_crissti @drg @tniles09 – Dremor May 10 '16 at 18:05
  • 1
    Dremor, I will but what happens if you have libgoo.so.0.12.0 and libgoo.so.0.13.1 ? Do you want to ln -sf ? – don_crissti May 10 '16 at 18:30
1

You're trying to set up an alternative set of ELF libraries for running an application, so instead of mucking with manually creating the symlinks, go straight to the intended application for the problem: ldconfig $HOME/.local/lib64/ should update all of the symlinks in the directory for you.

They won't always be .so.0 either, it will depend on the SOVERSION data in the ELF libraries.

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.