2

I have an issue with creating symbolic links with ln, with the relative and the force flag set.

The scenario is as follows:

$ tree
.
├── folder1
│   └── file
└── folder2

I create the link:

$ ln -sfr folder1/file folder2
$ tree
.
├── folder1
│   └── file
└── folder2
    └── file -> ../folder1/file

This is as I want it. But when I re-execute the command, I don't understand why the link is now pointing to itself:

$ ln -sfr folder1/file folder2
$ tree
.
├── folder1
│   └── file
└── folder2
    └── file -> file

Executing the command a third time corrects the error:

$ ln -sfr folder1/file folder2
$ tree
.
├── folder1
│   └── file
└── folder2
    └── file -> ../folder1/file

Re-executing the command multiple times toggles between two states. I really wonder why this is. According to the manual this should be no issue.

The ln version used (as shipped with Ubuntu 14.10):

$ ln --version
ln (GNU coreutils) 8.21
[...]
1

This is a bug and appears in the coreutils from version 8.16 to 8.21. It was fixed in 8.22. From the release notes of version 8.22:

ln --relative now updates existing symlinks correctly. Previously it based the relative link on the dereferenced path of an existing link. [This bug was introduced when --relative was added in coreutils-8.16.]

https://savannah.gnu.org/forum/forum.php?forum_id=7815

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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