Tag Archives: symbolic link

Ubuntu Server: How to Create a Symbolic Link Tips, Tricks and Tutorials 05 JUN 2015

Just as a quick note to myself because I’m doing this more often in server setups these days (which nevertheless is still infrequent enough that I need to drop notes for myself) – to create a symbolic link (symlink) on an Ubuntu server via the terminal, in particular to link to a folder, I need to use the ln command combined with the -s switch (The ln link command has a whole lot of uses, but we’re interested in symbolic links here).

The syntax is as follows:

ln -s <real folder> <link folder>

What the above achieves is a pseudo <link folder> which whatever you do inside it, actually happens in <real folder>. Nifty.

You can verify the symbolic link with the command ls -l which will show an arrow to where the link points.

red chain link

Related Link: http://manpages.ubuntu.com/manpages/vivid/man1/ln.1.html

XAMPP and Windows: How to Create a Symbolic Link Tips, Tricks and Tutorials 25 NOV 2014

If you have scripts which need to be run in your local web browser but fall outside of your web root or any other declared vhost directory, there is always the option of simply creating symbolic links to these external locations from within your web root folder.

To do this (and I needed to on my Windows 7 environment to get around some Sencha ajax origin restrictions during debugging) follow the following steps:

1. Click the Start button to bring up the start menu.

2. Type cmd in the universal search box at the bottom of the start menu. (You should see at the top of the search results under Programs cmd.exe highlighted)

3. Press the Ctrl + Shift + Enter to launch the command prompt (cmd.exe) as Administrator. If you don’t do this, you’ll get a error saying that there are insufficient permissions to create the symbolic link later on. (You can also right click and select “Run as Administrator” to achieve the same thing.)

4. A box saying “Windows needs your permission to continue” will pop up. Click Continue.

5. Go to the directory you want to create the link in. For example: cd c:\xampp\htdocs\

6. Use mklink to create your symbolic link (or shortcut):

mklink /D externalfolder "c:\Users\username\Documents\My Folder\"

Note: The /D is there because, in this example, we are linking to a directory. “externalfolder” is the name of the symbolic link (change to whatever you want). Finally, the path is where the symbolic link actually resolves to.

Using the example laid out below, we could now point our browser to http://localhost/externalfolder/hello-world.php which would run just fine, with the browser executing c:\Users\username\Documents\My Folder\hello-world.php in reality.

Useful little trick to be aware of.

xampp logo

Ubuntu Server: Dereference Symbolic Link Tips, Tricks and Tutorials 24 JUN 2014

Symbolic links in Linux is clever, I’ll give them that, but they are a headache, and quite often cause even more headaches than what they are worth as far as I’m concerned. Nevertheless, if you do you a colour-coded shell like the bash that I use on my Ubuntu server installs, then here is a quick way for viewing where exactly those misleading turquoise files and folder actually point to!

To dereference a symbolic link, use GNU readlink:

readlink -f /path/to/symlink

As an added bonus, if you want just the directory of the file a symbolic link links to, wrap everything up in a call to dirname:

dirname $(readlink -f /path/to/symlink)

And now you know exactly what that little bugger is pointing to.

ubuntu black and orange logo