0

So I have a find command as below which finds the libclntsh.so.* files in a directory instantclient.

find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*"

This results in for e.g.,

instantclient/libclntsh.so.11.1

How do I now ln within instantclient directory, ln -s libclntsh.so.11.1 libclntsh.so all with a find command in combination with exec

I should mention here that I DO NOT want to cd into instantclient. And this is for Alpine Linux.

nixgadget
  • 6,983
  • 16
  • 70
  • 103

1 Answers1

1

Use the -execdir option. As per manual:

-execdir command {} ;

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files.

So your command will be:

 find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*" -execdir ln -s {} libclntsh.so \;

EDIT:

Another solution

 find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*" | xargs -I {} sh -c 'ln -s $(basename {}) instantclient/libclntsh.so'
Marki555
  • 6,434
  • 3
  • 37
  • 59
  • Neither did I :) I was just checking how exactly `-exec` works and found it in the man page. – Marki555 Jun 12 '16 at 10:43
  • Is there an alternative to this ? `-execdir` doesnt exist as an option in Alpine Linux's find which is probably why i didnt see. – nixgadget Jun 12 '16 at 10:43