Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Oliver Salzburg Mar 18 at 8:13

  • This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
The question was cross-posted to Unix & Linux –  Oliver Salzburg Mar 18 at 8:13

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
-sv works the same way yes. But it tells you that something has gone wrong. Which probably is because you have it is a "borken" link –  giZm0 Oct 16 '12 at 10:05
1  
@giZm0 It does not output any error for me. As you can see in the manpage blockquote above, it should at least create it, even if it warns you that it doesn't link to something that exists: % mkdir a b % ln -sv a c ‘c’ -> ‘a’ % ln -sv b c ‘c/b’ -> ‘b’ –  zmode Oct 16 '12 at 10:10
    
As I have answered in the cross-post, specifying -ns makes ln fail as desired. -v is irrelevant to the outcome. –  A-B-B Apr 2 at 20:23

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