In *nix systems, symbolic links are quite useful in linking files or directories. When using symbolic links, there exists only one physical location of the file or directory; this allows you to create several symbolic links all pointing to a single source. Here’s a couple of use cases for symbolic links:
- When I was building my Asterisk PBX using an old Buffalo TeraStation, I started to run out of firmware space on my
/usrpartition, which was located on the system’s flash memory. Having limited space, I needed to use some other storage to store the binaries. With the system being a NAS, the obvious solution was to use the RAID array. So, I compiled all the binaries onto the RAID array and created symbolic links in my/usr/bindirectory. - In my work environment, I had a set of common Javascript libraries and two distinct application types that used those libraries: desktop applications and phone applications. I had originally started developing phone applications first and so I mistakenly placed my common Javascript libraries in the phone applications folder. In this case, I simply created a symbolic link in my desktop applications folder that pointed to the phone applications’ Javascript libraries folder.
The symbolic link, whether a file or folder, behaves exactly like a file or folder. If you edit the file, you’re actually editing the physical file. If you cd into the symbolically linked folder, your directory structure remains intact; once you cd into the folder, it will follow the folder structure of the physical directory:
<...>\dashboard\apps\desktop\resources>mklink /D resources \inetpub\wwwroot\dashboard\apps\mobile\resources <...>\dashboard\apps\desktop>cd resources <...>\dashboard\apps\desktop\resources>
The ability to create symbolic links is not limited to *nix systems, however. You can create symbolic links in NTFS file systems by using the mklink command:
C:\>mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
As an example:
C:\inetpub\wwwroot>mklink /D resources c:\inetpub\wwwroot\somedirectory\resources
symbolic link created for resources <<===>> c:\inetpub\wwwroot\somedirectory\resources
C:\inetpub\wwwroot>cd resources
C:\inetpub\wwwroot\resources>dir
Volume in drive C has no label.
Volume Serial Number is XXXX-NNNN
Directory of C:\inetpub\wwwroot\resources
02/08/2013 06:43 PM <DIR> .
02/08/2013 06:43 PM <DIR> ..
10/09/2012 05:08 PM <DIR> css
09/24/2012 04:53 PM <DIR> fonts
01/31/2013 12:13 PM <DIR> images
12/11/2012 03:04 PM <DIR> js
09/24/2012 04:49 PM <DIR> sass
02/08/2013 06:43 PM <DIR> sounds
07/09/2012 01:22 PM <DIR> svg
0 File(s) 0 bytes
9 Dir(s) 34,453,495,808 bytes free