One of the very powerful features of Linux file systems is symbolic links, more commonly known as soft links or simply symlinks. Symlinks make it much easier to get to a commonly used file or directory. Let’s assume we have a deep directory tree and want to make it easy to access
myfile within it:
$ mkdir -p deep/directory/tree
$ ln -s deep/directory/tree shortcut
$ touch shortcut/myfile
Now we can refer to that file as either
deep/directory/tree/myfile from the current directory.
Symlinks can point to other symlinks. For example, on the Debian system I’m typing this on,
/usr/bin/vim is a symlink:
$ file /usr/bin/vim
/usr/bin/vim: symbolic link to /etc/alternatives/vim
But the place it points to is also a symlink:
$ file /etc/alternatives/vim
/etc/alternatives/vim: symbolic link to /usr/bin/vim.gtk
That’s not an uncommon configuration to handle the
Finding the True Path
There’s a really simple what of finding out where the real file is:
realpath. Here it is in action:
$ realpath shortcut/myfile
$ realpath /usr/bin/vim
When we traverse symlinked directories to get to our working directory, it can even be confusing as to where we are, because
pwd will show the path with symlinks:
$ cd shortcut
realpath can show where we really are:
$ realpath .
Was This Linux Tip Useful?
Let us know in the comments below.