Ubuntu Server: Dereference Symbolic Link Tips, Tricks and Tutorials 24 JUN 2014

Symbolic links in Linux is clever, I’ll give them that, but they are a headache, and quite often cause even more headaches than what they are worth as far as I’m concerned. Nevertheless, if you do you a colour-coded shell like the bash that I use on my Ubuntu server installs, then here is a quick way for viewing where exactly those misleading turquoise files and folder actually point to!

To dereference a symbolic link, use GNU readlink:

readlink -f /path/to/symlink

As an added bonus, if you want just the directory of the file a symbolic link links to, wrap everything up in a call to dirname:

dirname $(readlink -f /path/to/symlink)

And now you know exactly what that little bugger is pointing to.

ubuntu black and orange logo

About Craig Lotter

Software developer, husband and dad to two young ladies. Writer behind An Exploring South African. I don't have time for myself any more.