`ln -s` creates a symlink inside an existing folder instead of failing

symlink

$mkdir lnTest1 lnTest2

$ln -s lnTest1 "lnTest2" There is NO slash at the end of "lnTest2"!!

$ls lnT* -Rl |sed "s'$USER''g"
lnTest1:
total 0

lnTest2:
total 0
lrwxrwxrwx 1   7 Jun 22 22:48 lnTest1 -> lnTest1

Best Answer

When the last argument to ln is a directory, the links are made in that directory. The man page says:

SYNOPSIS

    ln [OPTION]... TARGET... DIRECTORY     (3rd form)

In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.

It doesn't matter whether you're creating a hard or symbolic link. cp and mv behave similarly.

Related Question