I've symlinked a script file into my ~/bin, and when I do which foo the output is:


Is there a way to have this resolve the symlink and show me the real file?


use readlink

readlink -f "$(which command)"
  • Except the OP's /Users suggests he's on macOS and macOS' readlink doesn't support the -f option. – Stéphane Chazelas Aug 23 '17 at 9:28

With zsh:

print -r =foo(:A)

Or if foo is in the $cmd variable:

print -r $cmd:c:A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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