A symlink is a special type of file that contains a pointer to another file or directory on the filesystem. Historically, symlinks date back to the early 80′s where they were introduced on the Unix platform. They were designed to operate transparently to the user, where all programs access the symlink like a regular file, reading and writing as appropriate; unlike the commonly known Windows version, the Shortcut. Windows Shortcuts (.lnk) are somewhat like symlinks, allowing the user to jump around the filesystem in Windows Explorer, but the paradigm quickly breaks down when other applications attempt to use Shortcut files – they are just regular files at that point.
It surprised me to learn that, starting with Windows Vista and Windows Server 2008, the NTFS filesystem
supports the notion of symlink through the command line tool mklink. With mklink, a symbolic link can point to a file, directory, or even a remote network share. Where would this be handy?
How does it work? From a blog post at MSDN, open a command prompt in Vista under Administrator rights.
C:\test>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.C:\test>mklink foo c:\Windows\system32\notepad.exe
symbolic link created for foo <<===>> c:\Windows\system32\notepad.exeC:\test>dir
Volume in drive C has no label.
Volume Serial Number is 2211-7428Directory of C:\test
04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
04/14/2006 11:24 AM <SYMLINK> foo [c:\Windows\system32\notepad.exe]
1 File(s) 0 bytes
2 Dir(s) 69,238,722,560 bytes freeC:\test>mklink /d bar c:\windows
symbolic link created for bar <<===>> c:\windowsC:\test>dir
Volume in drive C has no label.
Volume Serial Number is 2211-7428Directory of C:\test
04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
04/14/2006 11:24 AM <SYMLINKD> bar [c:\windows]
04/14/2006 11:24 AM <SYMLINK> foo [c:\Windows\system32\notepad.exe]
1 File(s) 0 bytes
3 Dir(s) 69,238,722,560 bytes freeC:\test>del foo
C:\test>dir
Volume in drive C has no label.
Volume Serial Number is 2211-7428Directory of C:\test
04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
04/14/2006 11:24 AM <SYMLINKD> bar [c:\windows]
0 File(s) 0 bytes
3 Dir(s) 69,238,722,560 bytes freeC:\test>rd bar
C:\test>dir
Volume in drive C has no label.
Volume Serial Number is 2211-7428Directory of C:\test
04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 69,238,722,560 bytes free
Death to Shortcuts!
symbolic links are worthless if you are an MS Office (2007) shop since office cannot follow the links to save files.
Interesting, I didn’t know that. Thanks!
[...] Windows 7, relocating these directory locations involved editing the registry or creating symlinks to a new location. The alternative solution was to consciously redirect any circumstance that [...]