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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe 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.
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.
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.
ln -s ../../a/b/c
orln -s -T ../../a/b/c link