Server Fault is a question and answer site for system and network administrators. 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 have to determine the directory of a script which is symlinked.

/usr/local/bin/ (Symlink to the one above)

A cronjob executes /usr/local/bin/ Inside I am trying to determine where the original location is (which is /usr/local/src/myscript/ in this case). How to do that?

share|improve this question

The solution is

$( cd "$( dirname "`readlink ${BASH_SOURCE[0]}`" )" && pwd )
share|improve this answer
I'd even go for readlink -f to canonicalize even further. – Dennis Kaarsemaker Nov 21 '12 at 20:45

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.