Cross platform symlinks

Why a symlink

Many times when working with hosting apps, there comes a time or a need to have certain code in more than one place at the same time. To accomplish this, a ‘symlink’ can be used. For example, a basic NGinx or Apache server will have a path to host files on like /var/www/my-site/. It would not be recommended to have the code exist within that path directly though, as that would create a lot of complications when attempting to do simple updates or roll back code quickly. It’s much easier in this simple case to have /home/user/code/v1/ also be /var/www/my-site so when v2 is created, it can now be /var/www/my-site instead of v1. Symlinks allow for this, and are the preferred mechanism.

Symlink definition

In computing, a symbolic link (also symlink or soft link) is a term for any file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.
Wikipedia definition, 03-2018

In lamens terms, it’s an alias folder or file. In Windows logic, it’s like a shortcut (but not).

Creating a symlink

Depending on your OS, symlinks can be created with a command from Terminal or Command Prompt.

Here is a full script that can be used to create a symlink.

Removing a symlink

In the same flow, to remove a symlink cross-platform, here is the script.