Tracking any binary on linux

Let’s say you need to find out where your java installation is on linux.

First, the hard way:

which java
output of which java

Then, navigate through the links:

ls -l /usr/bin/java
output of ls -l /usr/bin/java

And again…

ls -l /etc/alternatives/java
output of ls -l /etc/alternatives/java

And again… Until it finds itself!

ls -l /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
output of ls -l /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java is the same link searched

Great! Now the easy way:

readlink -f $(which java)
output of the easy way!