First, a quick definition of terms. There are three kinds of ”symlinks” on Windows.
- soft links (also called symlinks, or symbolic links)
- hard links
- junctions (a type of soft link only for directories)
Soft links can be created for files or directories.
Hard links can only be created for files.
Both soft and hard links must be created on the same volume as the target. i.e. You can’t link something on
C: to something on
This is where the difference between soft and hard links is most evident.
Deleting the target will cause soft links to stop working. What it points to is gone. Hard links however will keep right on working until you delete the hard link itself. The hard link acts just like the original file, because for all intents and purposes, it is the original file.
Windows also has another type of link just for directories, called Junctions.
Junctions look and act like soft links. The key difference is that they allow you to link directories that are located on different local volumes (but still on the same computer). You can’t create a junction to a network location.
Create a soft link to a directory.
c:symlink_test> mklink symlink_dir real_dir
symbolic link created for symlink_dir > real_dir
Create junction link to a directory.
c:symlink_test> mklink /J junction_dir real_dir
Junction created for junction_dir > real_dir
Create a soft link to a file.
c:symlink_test> mklink symlink_file.txt real_file.txt
symbolic link created for symlink_file.txt > real_file.txt
Create a hard link to a file.
c:symlink_test> mklink /H hardlink_file.txt real_file.txt
Hardlink created for hardlink_file.txt > real_file.txt
What they look like.
Volume in drive C is OS
Volume Serial Number is 7688-08EC
Directory of c:symlink_test
06/07/2012 10:32 AM
06/07/2012 10:32 AM
06/07/2012 09:51 AM 15 hardlink_file.txt
06/07/2012 09:59 AM
06/07/2012 09:47 AM
06/07/2012 09:51 AM 15 real_file.txt
06/07/2012 10:00 AM
06/07/2012 10:31 AM
3 File(s) 30 bytes
5 Dir(s) 145,497,268,224 bytes free
Note for PowerShell users:
MKLINK isn’t an executable that you can just call from PowerShell. You have to call it through the command prompt.
cmd /c mklink /D symlink_dir real_dir
Alternatively, you can use this module I wrote that has native PowerShell wrappers for MKLINK.
FSUTIL is another way to create hard links (but not soft links). This is the same as
c:symlink_test> where fsutil
c:symlink_test> fsutil hardlink create hardlink_file.txt real_file.txt
Hardlink created for c:symlink_testhardlink_file.txt > c:symlink_testreal_file.txt
Junction is a tool provided by Sysinternals and provides another way to create junctions. Same as
mklink /J. It also has some other tools for working with junctions that I won’t cover here.
c:symlink_test> junction junction_dir real_dir
Junction v1.06 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
Targetted at: c:symlink_testreal_dir
Read more about hardlinks and junctions on MSDN.