Symbolic link on Windows
If you are on Windows and you miss symbolic links, do not despair: NTFS supports symlink since Windows Vista. Try
the mklink
built-in 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.
Using cygwin? The following shell script leverages mklink
from your beloved shell.
Please note the more familiar, ln -s
like, syntax order for Target
and Link
params.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# A simple cygwin script to create symbolic link on NTFS, | |
# leveraging the MKLINK command (built-in since Windows Vista) | |
# | |
usage () { | |
echo "usage: $0 EXISTING_TARGET LINK_NAME" | |
exit 1 | |
} | |
if [ $# -lt 2 ]; then | |
usage | |
fi | |
if [ ! -d "$1" ] && [ ! -f "$1" ]; then | |
echo "TARGET directory or file '$1' does NOT exist" | |
usage | |
fi | |
TYPE="" | |
if [ -d "$1" ]; then | |
# create a directory simlink default is file | |
TYPE="/d" | |
fi | |
FROM=`cygpath -aw $1` | |
TO=`cygpath -aw $2` | |
MKLINK="mklink "$TYPE" "$TO" "$FROM"" | |
cmd /c "$MKLINK" |
Wondering what a symbolic link is? From Wikipedia:
An NTFS symbolic link (symlink) is a filesystem object in the NTFS filesystem that points to another filesystem object. The object being pointed to is called the target. Symbolic links should be transparent to users; the links appear as normal files or directories, and can be acted upon by the user or application in exactly the same manner.