例如从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检查或类似的操作(非常尴尬)会很好。
[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