In order to change a symbolic link, one can use the -fs option to eliminate the need to unlink or delete the old link first. However, trying to do so on directories does not seem to work:
$ mkdir dir1
$ mkdir dir2
$ ln -s dir1 lnk
$ ln -sf dir2 lnk
$ ll
......... lnk -> dir1
$
Why so? Is there another option to do this with directories the same as with files?
By default, if you pass a directory (or a symlink to a directory) as the second argument to the
ln
command, it will create a link inside that directory with the same name as the first argument. So with the set of commands you have issued, you should find a symlink nameddir2
insidedir1
.You can change this behaviour using the
-T
option:If you pass this option in your second
ln
invocation, then it should overwrite thelnk
symlink rather than creating a new symlink inside the first directory.