To some this may seem like a trivial task, but I see great interest from Unix/Linux beginners arriving to this blog: how exactly does one confirm what a symlink points to?
First of all, if you haven't already done so – read my Unix Symlink Example post to learn what a symlink is and to refresh your mind about creating symlinks.
If you're still reading, perhaps a bit more explanations are needed.
Since symlink is nothing but a special Unix file, you can use all the standard Unix commands to work with it – list it or remove it for example.
Listing symlinks
For listing files, the most obvious choice is a Unix ls command, and the way you use it to list symlink is the same way you'd list any other file:
ubuntu$ ls ubuntu-release ubuntu-release
Now we come to exactly the reason why some people don't find working with symlinks obvious: when we list the symlink, we expect to see the file it points to. More precisely, we expect to see the name of this file.
Showing what a symlink points to
To show what a symlink points to, you need to use a long format of the ls command:
ubuntu$ ls -l ubuntu-release lrwxrwxrwx 1 greys greys 10 2008-03-23 16:53 ubuntu-release -> /etc/issue
As you can see, the ubuntu-release symlink points to the /etc/issue file.
Robert says
For those writing scripts there is another way to show where a link points to: the UNIX command readlink.