How to Symlink a File in Mac OS X

12.25.2014

According to Wikipedia, a symbolic link (also symlink or soft link) is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.

I think it’s a fancy way of saying a shortcut from one file or directory to another. This is best illustrated with an example.

From this stack overflow question, the symlink command looks like this:

ln -s /path/to/file /path/to/symlink

It’s difficult to imagine when you would actually need this until you actually need it. So for a while during my early days of web development, symlinks were a mystery to me. Though recently, I did have a use for it. I needed to symlink my WordPress theme files into the htdocs folder in MAMP that contains my WordPress installation.

ln -s ~/Code/travisluong /Applications/MAMP/htdocs/travisluong.com/wp-content/themes/travisluong

The reason for this was to keep my git repositories all organized in the Code folder. There are many other uses for symlinks, but this is just one example.