Symlink Directories on OSX

Symlink Directories on OSX

The OSX version of the ln command behaves differently than the GNU version. As a result, I could not figure out a way to correctly symlink an entire directory (and its contents) on OSX. Here's a quick solution to this problem:

This command will install and allow you to use GNU command line tools on OSX:

$ brew install coreutils

Then you can use gln (short for GNU ln) as such:


The s flag makes symbolic links instead of hard links and the r flag makes the command run recursively on subdocuments/subdirectories.

For example, if I wanted to symlink an entire directory called docs/ into a directory called api_docs/content/ I would use the following command:

$ gln -sr docs/ api_docs/content/

This saves me from having to copy over all of the contents of docs/.