When running (on linux different ubuntu variations):
>ln -s dir_1 symlink_dir >ln -s dir_2 symlink_dir It fails without telling that it fails. But if you do the same thing on a file instead or, add v to the option it does tell you that it fails:
>ln -s file_1 symlinkg_file >ln -s file_2 symlinkg_file or
>ln -sv dir_1 symlink_dir >ln -sv dir_2 symlink_dir It fails with the error msg:
ln: failed to create symbolic link For me this seems to be a very strange behaviour? Is there a reason for this?
11 Answer
It does not actually fail. It creates your link inside the given directory:
% mkdir dir_1 dir_2 % ln -s dir_1 symlink_dir % ln -s dir_2 symlink_dir % ls -l total 0 drwxr-xr-x 2 user group 60 Oct 16 12:47 dir_1 drwxr-xr-x 2 user group 40 Oct 16 12:47 dir_2 lrwxrwxrwx 1 user group 5 Oct 16 12:47 symlink_dir -> dir_1 % ls -l dir_1 total 0 lrwxrwxrwx 1 user group 5 Oct 16 12:47 dir_2 -> dir_2 This behaviour is described in the manpage:
ln [OPTION]... TARGET... DIRECTORY (3rd form) ... In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. However, this link fails to link back to dir_2 as it is not set properly. This is also expected behaviour though, and not meant to fail. From the manpage:
Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.
By the way, it works the same way for me even with -sv. Maybe you are using a different implementation of ln. Are you sure you are not using -T? Maybe that is set in your ~/.bashrc/~/.zshrc/etc. Try which ln.