how to find real file from link

ls -l java
lrwxrwxrwx 1 root root 22 2019-02-17 11:37 java -> /etc/anotherLink/java

when I do ls -l it shows path to file, but that file can also be a link. is there any way to show path to real file?


Solution 1:

I think what you want is readlink:

readlink -f java

To find this, I asked which manual page might by appropriate for symbolic links.

apropos "symbolic link"

It returned a reference to readlink, so I used the manual:

man readlink

I read the manual page:

-f, --canonicalize canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist

Is this what you are looking for?

Solution 2:

Try using file command.

It shows details about a given file (type, contents format)

Example:

$ cp -s temp.sh temp2.sh
$ file temp2.sh 
temp2.sh: symbolic link to `temp.sh'