ln -T do? I know the flag does not exist in the BSD version of
ln, and it only exists in the GNU version, and I have read the documentation that it will make
LINK_NAME as a normal file always", but what does that mean and why does the BSD version not have it?
--no-target-directory) option to GNU
ln provides a safety feature that may be useful in scripts.
Suppose that you want to create a new name,
$newname, for a file
$filename, where the new name is maybe provided from external sources.
ln -T "$filename" "$newname"
would then fail if
$newname was an already existing directory, instead of unexpectedly creating the name
$filename inside that directory (which may cause further operations to fail in hilarious ways).
It's a shortcut for something like
if [ ! -e "$newname" ]; then ln "$filename" "$newname" else printf 'failed to create hard link "%s": File exists\n' "$newname" >&2 # Further code to handle failure to create link here. fi
--target-directory) provides a way of ensuring that the new name for the file is actually created inside an existing directory, and nowhere else.
Also, as pointed out by Stephen Kitt in comments, moving the test on the filetype of the target/"link name" into the utility itself may also decrease the risk of being affected by the race condition whereby the target is changed in-between testing for its existence and/or type and actually creating the link.
Why does POSIX or BSD not have
-t? Well, GNU tool in general have many extensions added that provide convenience. The
-t options to
ln are some of these. They don't really let you do something that couldn't be done without them, and they don't add functionality. Some systems, like the BSDs, have not even considered adding them, or have considered but rejected the idea of adding them (I don't really know, I can't recall seeing anyone send in a patch to add it on the
openbsd-tech mailing list, for example).