Symbolic links on a Mac (OS X) →

Posted on January 23, 2012 in Development with 0 comments.

If you are a developer and have not come across symbolic links before, then you need to read this blog post. Symbolic links are extremely useful if you hate copying and pasting duplicate files and folders in different places/projects.

So what exactly are they? Simply speaking, they are a virtual link or shortcut between a file or folder from a different file/folder location.

So for instance, I have a project that I am working on in a directory called ‘Example-Project’ that lives in a ‘Projects’ directory. Let’s say that this is a WordPress site. Now, I also have a plugin that I have written called ‘Display-Latest-Posts’ and this plugin also sits in the main ‘Projects’ directory. Now, I want to use this plugin on the Example-Project site.

There are two ways in which we can do this

  1. Copy/Paste the plugin files from ‘Display-Latest-Posts’ into ‘Projects/Example-Project/wp-content/plugins/’
  2. Create a symbolic link

The problem with method number 1 above, is that if I change some code in the ‘Display-Latest-Posts’ plugin, I have to go and copy/paste the files I changed back into the ‘Example-Project’ folder. Now imagine that you have the plugin running on a number of sites in your development environment. That could take a while.

Introducing symbolic links

Symbolic links solve the problem that I just mentioned. When you create a symbolic link in a folder, any changes to the files in the original folder will be reflected in the linked folder, since the linked folder is actually just a reference/shortcut of the original folder. It is not two separate folders.

To create a symbolic link, open terminal and type the following:

ln -s /Path/to/original/folder New-folder-name

So in our example above, we would have created the following symbolic link:

ln -s /Projects/Display-Latest-Posts /Projects/Example-Project/wp-content/plugins/Display-Latest-Posts

The symbolic link is now created between those two folders and our plugin will now be working in our Example-Project site.

Symbolic links are really easy to use and can save you tons of time. Give them a try.

Tagged with

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>