2

When creating a softlink how do add the path, I did the following:

ln -s file1.txt /home/user9000/Desktop/SymbolicLink.txt

When I see the softlink on the desktop it marks that the doc doesn't exist.

Am I doing something wrong?

  • You need to use the full path of the file to which you're linking. – HalosGhost Aug 09 '14 at 20:37
  • To create a relative link, and have auto-completion help you, then first cd to directory that you want the link in. Then ln -s ../../a/b/c or ln -s -T ../../a/b/c link – ctrl-alt-delor Aug 10 '14 at 22:28

3 Answers3

3

The syntax of ln may seem counter-intuitive at first until you see the rationale behind it.

The syntax (for soft link creation) is

ln -s <TARGET> <LINK_NAME>

where <TARGET> is interpreted relative to the location of the soft link.

So when you say something like:

ln -s file1.txt /home/user9000/Desktop/SymbolicLink.txt

This means create the file /home/user9000/Desktop/SymbolicLink.txt as a symbolic link to the file /home/user9000/Desktop/file1.txt.

My guess is, you're trying to link to file1 which is in the current working directory. In such a case, you'll need to give its full path as in vinc17's answer

Note that if you create SymbolicLink.txt with the command you have shown above, it has the interesting side effect that whenever you move it to any other directory, it will be a symbolic link to a file named file1 in that directory. Whereas if you supply the full path to file1, the link will always point to that file no matter where you place it in that machine.

Joseph R.
  • 39,549
2

Your link is incorrect. You need:

ln -s "$PWD/file1.txt" /home/user9000/Desktop/SymbolicLink.txt

You can also create a relative link (starting with ../), but I suggest that you cd to /home/user9000/Desktop first to avoid making a mistake.

vinc17
  • 12,174
-1

Yes, the UI behaves differently. A softlink won't be shown as a icon in desktop. You need to copy and paste the file there or create a link using the graphical interface itself.