我 rsync 目录“Promotion”,其中包含具有不同目录结构的两台计算机之间的绝对符号链接。因此绝对符号链接在两台机器上都不起作用。为了使它们工作,我想将它们转换为相对链接。目录结构是
Machine 1: /home/user/Privat/Uni Kram/Promotion/
Machine 2: /homes/user/Promotion/
Run Code Online (Sandbox Code Playgroud)
以下是两个示例符号链接:
4821 1 lrwxrwxrwx 1 manu users 105 Nov 17 2014 ./Planung\ nach\ Priorit\303\244ten.ods -> /home/manu/Dokumente/Privat/Uni\ Kram/Promotion/Pl\303\244ne\ und\ Ideen/Pl\303\244ne/Planung\ nach\ Priorit\303\244ten.ods
37675 1 lrwxrwxrwx 1 manu users 102 Aug 3 2015 ./Kurs/Lab\ Course\ Somewhere -> /home/manu/Dokumente/Privat/Uni\ Kram/Promotion/Workshops\ &\ Fortbildungen/Kurs\ Lab\ Course\ Somewhere
Run Code Online (Sandbox Code Playgroud)
我的非工作尝试是(基于示例):
find * -type l -print | while read l; do
ln -srf $(cut -c 24- < $(readlink $l)) $l;
done
Run Code Online (Sandbox Code Playgroud)
在包含正确符号链接文件的计算机上,运行以下命令:
find . -type l -exec ln -sfr {} . \;
Run Code Online (Sandbox Code Playgroud)
要仅更改当前目录中的符号链接而不遍历所有子目录,请使用该-maxdepth 1标志,因为上述命令会将子目录中的符号链接移动到当前目录中。
此外,macos 提供的本机 BSDln命令没有标志-r,但ln可以使用 GNU core utils 提供的命令来代替,如果通过 homebrew 安装,则g在lnie 前面添加。gln -sfr