查找和软 link 没有父路径

Find and soft link without the parent path

所以我有一个如下所示的查找命令,它在目录 instantclient.

中查找 libclntsh.so.* 文件
find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*"

这导致例如

instantclient/libclntsh.so.11.1

我现在如何 lninstantclient 目录中,ln -s libclntsh.so.11.1 libclntsh.so 全部使用 find 命令与 exec

我应该在这里提到我不想 cd 变成 instantclient。 这是 Alpine Linux.

使用-execdir选项。根据手册:

-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.

因此您的命令将是:

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

编辑:

另一个解决方案

 find instantclient -type f -name "*libclntsh\.so\.[0-9]*\.[0-9]*" | xargs -I {} sh -c 'ln -s $(basename {}) instantclient/libclntsh.so'