Dereference symbolic link in OS X?

Solution 1:

The most straightforward solution is to test the return value and prepend pwd if you find that the readlink has returned a relative path rather than an absolute path stored in the link. Anything not starting with / is simple to test with a variety of unix tools.


I don't know if this was a conscious design decision since OS X prefers file system aliases which track a file's unique id as well as the path or is just an omission / difference carried forth from BSD. What is clear is that there is no option to synthesize the full path of the linked file using the OS X version of readlink.

Here are several ready made solutions to implement read link -f on OS X from another site...

  • https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac

If you are a fan of GNU tools, you'll want to get homebrew and install the coreutils package - you can then alias greadlink for readlink and carry on with a minimal amount of fuss.