例如,从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检查或类似的东西,那就太好了,因为目前它做得很笨拙。
BSDln -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
与。
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