Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
thought about reading the man page of ls? –  steabert Jan 16 '12 at 14:31
add comment

1 Answer

up vote 3 down vote accepted

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 named dir2 inside dir1.

You can change this behaviour using the -T option:

-T, --no-target-directory
       treat LINK_NAME as a normal file

If you pass this option in your second ln invocation, then it should overwrite the lnk symlink rather than creating a new symlink inside the first directory.

share|improve this answer
    
Definitely does the job. –  ysap Jan 16 '12 at 7:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.