How can I get the behavior of GNU's readlink -f on a Mac?

troelskn picture troelskn · Jun 28, 2009 · Viewed 130.1k times · Source

On Linux, the readlink utility accepts an option -f that follows additional links. This doesn't seem to work on Mac and possibly BSD based systems. What would the equivalent be?

Here's some debug information:

$ which readlink; readlink -f
/usr/bin/readlink
readlink: illegal option -f
usage: readlink [-n] [file ...]

Answer

tomyjwu picture tomyjwu · Oct 27, 2010

MacPorts and Homebrew provide a coreutils package containing greadlink (GNU readlink). Credit to Michael Kallweitt post in mackb.com.

brew install coreutils

greadlink -f file.txt