是否有类似的标志(如Linux的Mac osX中的ln -sh跳过已进行符号链接的任何文件?

问题描述 投票:0回答:1

例如从Mac手册页:

 man ln 


     -h     If the NewLinkFile (or directory) is a symbolic link, do not follow
            it.  This is most useful with the -f option, to replace a symlink
            which can point to a directory.

我正在编写一个脚本,该脚本每天一次遍历数百个文件并对其进行符号链接,然后每天定期检查新文件并对其进行符号链接。使用此-h检查或类似的操作(非常尴尬)会很好。

unix symlink
1个回答
0
投票

[BSD ln -sh的GNU等效项是ln -sn

但是GNU的ln -sT更安全,因为它将跳过符号链接和目录。

比较:

cd "$(mktemp -d)"
mkdir bin
for d in bin usr etc; do ln -sn "/$d" "$d"; done
   # will create a bin/bin -> /bin symlink

vs。

cd "$(mktemp -d)"
mkdir bin
for d in bin usr etc; do ln -sT "/$d" "$d"; done

ln: failed to create symbolic link 'bin': File exists
© www.soinside.com 2019 - 2024. All rights reserved.