Symbolic Links – How to Find the Original File

symlink

So let's say I have a symbolic link of a file in my home directory to another file on a different partition. How would I find the target location of the linked file? By this, I mean, let's say I have file2 in /home/user/; but it's a symbolic link to another file1. How would I find file1 without manually having to go through each partition/directory to find the file?

Best Answer

Try this :

readlink -f /path/file

( last target of your symlink if there's more than one level )

If you just want the next level of symbolic link, use :

readlink /path/file

Edit 2020:

now, GNU coreutils own realpath :

realpath /path/file

similar to readlink -f by default

Related Question