Sometimes happen that you find a sequence of links, and so you should start to follow them to see exactly what command are you about to run, or the directory used in that symbolic link, or you can use readlink.
readlink it’s contained in the package coreutils, so you should already have it.
The basic usage is
readlink symbolic link and this give as output the full path of the real file following all the symbolic links.
Let’s say that we have something like that:
-rw-r--r-- 1 linuxaria linuxaria 8 2011-06-24 21:45 one drwxr-xr-x 2 linuxaria linuxaria 4096 2011-06-24 21:46 two ./two: lrwxrwxrwx 1 linuxaria linuxaria 3 2011-06-24 21:44 link -> one lrwxrwxrwx 1 linuxaria linuxaria 6 2011-06-24 21:46 one -> ../one lrwxrwxrwx 1 linuxaria linuxaria 8 2011-06-24 21:44 three -> two/link lrwxrwxrwx 1 linuxaria linuxaria 5 2011-06-24 21:43 four -> three
So basically four it’s a symlink, that after many links , arrive to the file one.
#readlink four three #readlink -f four /tmp/one
So without options it gives as output the first link, while with -f it canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist
Now I delete the file two/link
#rm two/link #readlink -f four /tmp/two/link
As expected this time the link stop to the last link available.
Another example is
#readlink -f /proc/$$/exe /bin/zsh4
This give you exactly the full path of the shell that you are using.
- How to easily record your screen on Linux
- Bitdefender a good antivirus for Linux systems
- Apotheon: A heroic action game released for Linux
Find me on Google+