Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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.