1

I created a symbolic link for a file named zotero.desktop to be placed in the directory ~/.local/share/applications, as below:

<At source file's directory>$ ln -s zotero.desktop ~/.local/share/applications/

the symbolic link got created, but was broken and did not work. Also, tried double-clicking on the file Ubuntu Desktop, but had the alert of "Boken link".

Then tried the below command, and it worked:

<At ~/.local/share/applications/>$ ln -s <source-dir>/zotero.desktop .

Is there any explanation for this?

2

The command ln -s zotero.desktop ~/.local/share/applications/ creates the softlink ~/.local/share/applications/zotero.desktop which points to itself, ~/.local/share/applications/zotero.desktop:

$ ls -l ~/.local/share/applications/zotero.desktop 
lrwxrwxrwx 1 terdon terdon 14 May 29 11:33 /home/terdon/.local/share/applications/zotero.desktop -> zotero.desktop

This is because the format of the ln command is:

ln source target

Since you gave the source as a file name, without a path, that is taken to be a file name in the target directory. I don't know where your target is, but assuming it is in the directory you ran the ln command from, you want to run this:

rm ~/.local/share/applications/zotero.desktop
ln -s "$PWD/zotero.desktop" ~/.local/share/applications/

In general, you need to remember that softlinks are relative. So for example, I can do this:

$ tree
.
├── file
└── foo

1 directory, 1 file
$ ln -s ../file foo/
terdon@tpad foo $ tree
.
├── file
└── foo
    └── file -> ../file

When I ran ln -s ../file foo, that means "create a symlink in the directory foo which points to ../file". But the ../file will be with respect to the symlink. So it will point to a file called file above the directory foo.

The simplest way to always get it right is to move into the target directory first and then run the ln command there, so that you get the relative path right.

| improve this answer | |

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.