Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I needed to issue several commands to follow a chain of symbolic links to the final target.

Is there a command which will do it in a single step?

which updatedb

ls -l /usr/bin/updatedb  
lrwxrwxrwx 1 root root 26 2010-09-01 16:22 /usr/bin/updatedb -> /etc/alternatives/updatedb  

ls -l /etc/alternatives/updatedb  
lrwxrwxrwx 1 root root 25 2010-09-01 16:21 /etc/alternatives/updatedb -> /usr/bin/updatedb.mlocate  

ls -l /usr/bin/updatedb.mlocate  
-rwxr-xr-x 1 root root 34492 2010-03-24 21:16 /usr/bin/updatedb.mlocate  
share|improve this question
up vote 7 down vote accepted

Use readlink -e <linkfile>. See readlink's manpage for more info on its arguments.

share|improve this answer
Thanks, it works nicely.... and I've just now found another one called chase which has a few extra options, eg. output the list of links it follows. ("chase" is in the Ubuntu repository)... – Peter.O Dec 16 '10 at 22:35
Keep in mind that this is the GNU version of readlink. Perfectly fine on Ubuntu, but you may get bitten when you attempt similar stunts on other unixoid systems. Just saying. +1 – 0xC0000022L Jan 10 '13 at 19:30

There was a similar question including solutions on stackoverflow.

share|improve this answer
Thanks wag... The answers presented on stackoverlfow are a bit more than I need.. They are intended for processing each symbolic link found.. I just want the final real file... but it is a good reference link for that more detailed requreme – Peter.O Dec 17 '10 at 3:00
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Eliah Kagan Dec 31 '12 at 1:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.