Windows

Be more efficient and better organized with the MKLink symbolic link tool

Greg Shultz explains in detail what a symbolic link is and shows you how to use the MKLink in Windows 7 to simply file management.

If you are like most folks who have been using Microsoft Windows for quite some time, chances are good that you create and use shortcuts quite regularly. As you know, shortcuts can save you time and effort when it comes to quickly accessing applications or folders. While creating and using these types of standard shortcuts is quite simple, Windows 7 and Vista come with a tool called MKLink for creating a more advanced type of shortcut called a symbolic link.

In this edition of the Windows Desktop Report, I'll explain in more detail what a symbolic link is and show you how to use the MKLink tool. I'll then show how I use symbolic links to simplify file management.

This blog post is also available in PDF format in a TechRepublic download.

What is a symbolic link?

As I alluded to in the introduction, a symbolic link is essentially a more advanced type of shortcut. More specifically, a symbolic link is a file-system object that points to another file system object. The file system object can be either a file or a folder. Symbolic links are transparent to users because the links appear as normal files or folder and can be accessed by applications as well as users in exactly the same manner. Keep this thought in mind as we explore MKLink tool.

The MKLink tool

In order to use the MKLink tool, you have to open a command prompt in administrator mode.

  1. Click the Start button.
  2. Type CMD in the Start Search box.
  3. Press and hold down [Ctrl]+[Shift]+[Enter].

When you do, you will encounter a UAC dialog box and will have to respond accordingly.

When the Administrative command prompt window appears, just type mklink and you will see the tools syntax description, as shown in Figure A.

Figure A

Using the MKLink tool on the command line is easy.

As you can see, the default command (without any options) will create a symbolic link to a file. For example, the command:

mklink pad.exe notepad.exe

will create a file symbolic link where typing pad.exe will allow you to launch notepad.exe.

Using the /D option will create a symbolic link to a folder. For example, the command:

mklink /D c:\one c:\two\three\four

creates a symbolic link called one, which points to the folder called four.

The /H option will create a hard link rather than a symbolic link. The difference between a hard link and a symbolic link is that instead of working like a shortcut, a hard link is more like renaming the file. For example, the command:

mklink /H pad.exe notepad.exe

makes the operating system treat pad.exe as if it were actually notepad.exe.

Finally, the /J option will create a hard link to a folder. This is also called a Directory Junction (a.k.a. junction point) and instead of working like a shortcut to a folder, a hard link works more like a regular folder. For example, the command:

mklink /J c:\one c:\two\three\four

makes the operating system work with the long directory structure c:\two\three\four just as if it were a single directory named c:\one.

When you're finished with any one of these types of symbolic links, you can terminate the link simply by deleting the link. For example, to terminate the one hard link, you'd simply delete the c:\one folder. However, since the link is terminated first and c:\one folder is actually empty, you needn't be concerned about data loss in the c:\two\three\four folder.

The CurrentWork example

Back in the Windows 2000 days, I developed my CurrentWork file-management technique to reduce the amount of time and effort I spent navigating my very detailed-oriented folder organizational structure. To do so, I used a command-line tool called Linkd.exe from the Windows 2000 Resource Kit. (The old Linkd tool worked similarly to the current MKLink tool.) Now that I'm using Windows 7, I'm using the MKLink tool.

To use this technique, I use the MKLink tool to create a symbolic link that creates the C:\CurrentWork folder and redirects it to a folder deeply nested in the folder structure that I use to keep my work organized. For example, the target folder could have the path:

C:\Users\Greg Shultz\My Documents\Articles\TechRepublic\2010\9) September 10 \9-3

As I finish an assignment, I remove that symbolic link and create a new one for the next assignment. Of course, this means that the target folder is always changing as I move from assignment to assignment. However, once I create the new symbolic link, the only folder name I have to navigate to when opening, saving, or copying files related to the assignment is the C:\ CurrentWork folder. This has saved me an immeasurable amount of time and frustration.

For example, before writing this article, I used the command

Mklink /J C:\CurrentWork "C:\Users\Greg Shultz\My Documents\Articles\TechRepublic\2010\9) September 10\9-3"

As you can see, since I'm working on the command line and the target path contains long names with spaces, I have to enclose the target path in double quotes. However, even though the path is very long, while I was working on this article, the only folder I had to remember was CurrentWork.

What's your take?

Now that you see how easy it is to create your own symbolic links, will you apply this example to the way you work? Are you already using symbolic links and the MKLink tool in Windows 7? If so, what has been your experience? As always, if you have comments or information to share about this topic, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

Stay on top of the latest Microsoft Windows tips and tricks with TechRepublic's Windows Desktop newsletter, delivered every Monday and Thursday. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

38 comments
drediess
drediess

I thought of a great way to add the "Favorites" shortcuts from Windows Explorer into the Start Menu for easy access in Wiin 7 Pro. I had to first delete the "Favorites" folder from my user directory (which means you will be replacing the bookmarks folder for Internet Explorer, but if you use Chrome or Firefox this won't make a difference). Then running CMD as Admin, I used: [b][q]C:\Windows\system32>mklink /D %userprofile%\Favorites %userprofile%\Links[/q][/b] And got the following success message: [b][q]symbolic link created for C:\Users\...\Favorites C:\Users\...\Links[/q][/b] Now, the same shortcuts I use all the time in folder windows are conveniently nested in the Favorites tab of my start menu. (Of course you have to enable Favorites to be shown in the start menu properties). Super Handy!!

ChrisHyche@AlabamaOne.Org
ChrisHyche@AlabamaOne.Org

One thing I tried to to create a symbolic link in my "Documents on MWDevice" folder. It working in syncing all of the files in the linked to folder on my device. Now if only I could my the link read-only somehow so the device can't write back to the linked folder.

RTHJr
RTHJr

I have advocated the use of SymLinks as a means to redirect commonly planted cache, log, queue, and temp files that cause fragmentation, performance bottleneck, and wear and tear of the system partition and hard disk. If a SymLink tool was built in the OS, we could redirect a lot of the frequent data writes away from where the OS lives so the OS becomes more like an image that loads into memory and only is written to when patched. I call it the "Volatile Volume" where log files can go and be a central source point for logs and troubleshooting logs when a system goes down and for copying those logs off into a central repository. The idea is that the Volatile Volume can be a suicide disk by design so because much of the data is just volatile (temp files) and/or reproduceable (print job). This same concept has good implication for VDI as well where logical Volatile Volume VHDs can all physically be hosted on a physical Volatile Volume designated hard, "suicide" disk. See the Volatile Volume Concept: http://www.gliffy.com/publish/1841408/ NOTE: the concept depicts the use of an ?Applications Hive?, which TechRepublic blog member Nicholas has articulated rather well on another post in ?How to save the PC: A petition to Microsoft and Apple?: http://blogs.techrepublic.com.com/hiner/?p=2941 This is so the registry of applications is not blown away when the OS is blown away with a fresh image. It would be helpful if Microsoft developed an Applications Hive. VDI Volatile Volume: http://www.gliffy.com/publish/1849359/ You can think of this as SymLinks on steroids.

hscowan
hscowan

Hi Greg et al, this is an interesting article and I think a useful shortcut method. However it is dangerous to give partial explanations. If you make a shortcut to notepad as demonstrated, you can easily use the delete/erase command to remove the symbolic link and notepad is unscathed. Likewise C:\Windows\System32>mklink jz "C:\Users\your user name\Documents\zzzzz\joke.d ocx" symbolic link created for jz C:\Users\your user name\Documents\zzzzz\joke.docx del jz Original file is still intact. But if you symbolically link to a folder as here: C:\Windows\System32>mklink /D zz "C:\Users\your user name\Documents\zzzzz" the link is fine until you want to 'remove' it. Initiating the del/erase command will not remove the link - but it WILL delete all the files in the linked folder! Luckily there is a confirmation prompt, but... RMDIR will remove the link, and seems to be safe, leaving the linked folder intact. HTH, Scott

lhgordon
lhgordon

Please note mklink is powerfull but also has a disavantage: Tools that measure the sise of files on your hard drive get confused with links and report the wrong size. Most noticable is the size of WinSxS in Vista and W7. If you don't care about false size readings use mklink, but if you do, use shortcuts or a batch file with a "Run" command.

eclas
eclas

I still don't see a major advantage over a normal shortcut. You want a ref to a deeply nested folder so u make a shortut pointing to it and then name the shortcut whatever you like. What's the difference other than you can create the folder when you create the shortcut with MKLink? With the standard shortcut you just need to create the folder 1st and then just use the shortcut after that. What am I missing?

Mark W. Kaelin
Mark W. Kaelin

Now that you see how easy it is to create your own symbolic links, will you apply this example to the way you work? Are you already using symbolic links and the MKLink tool in Windows 7? If so, what has been your experience?

lhgordon
lhgordon

Mklink has a downside. Tools that measure the size of a file or directory get confused and report the wrong size of links. The most noteable is the WinSxS directory in Vista and Windows-7. If you con't care about incorrect file and folder sizes use mklink. If you do care use shortcuts or Batch files with run commands.

RTHJr
RTHJr

SymLinks are scriptable where they can be called on in a script and the processor then will be passed whatever files the SymLink is pointing to. But a shortcut IS a file itself. A script then ends up trying to execute that file instead of the file the shortcut is pointing to. I have a SymLink of my C:\Program Files to my G:Program Files even though my %Program Files% environment variable tells all install programs where to go to the G: drive. BUT, some utilities, including MS Office VB support, wants to go to the C: drive anyway. So having the SymLink there assures that all my program files go to the correct drive. A Shortcut cannot do that for me.

pmansbach
pmansbach

I believe that you can access files and directories under the destination directory with the links, but not with the shortcut. For example, "\one\subdir\prog.exe" will work with the "one" link, but wouldn't work if it were a shortcut. (Haven't tested this, no time today, sorry)

pcbrawner
pcbrawner

I'm with you...maybe I'm just thick headed but I don't see any substantial advantage of this over normal shortcuts except maybe obfuscation for someone coming along after you trying to figure it out.

RTHJr
RTHJr

I found out that older Junction point tools such as the Sysinternals Junction.exe and the old 2000 Resource Kit LinkD.exe cannot create links to other hosts but only the local machine with logical drives. UNCs of the NetBIOS form \\RemoteComputer\ do not work. In talking with other technicians how to work around this, if you have Windows Server 2000 or 2003 then you can install DFS on the remote machine with a DFS link, install DFS again on your local host (must be a Windows Server) AND setup a cross-link DFS link otherwise known as double linking or deep linking. This is because the local DFS link then appears as rooted on a local drive. On a 2008 machine, you do not have to do this because SymLink is supported out of the box with UNC support.

RTHJr
RTHJr

I am going to use SymLinks to build images. I have a smattering of ISOs, WIMs, and VHDs that I find I copy into folder for a script to run against. I am going to use SymLinks instead of copying those files so as to save on disk space on external drives and rid of big duplicate files.

alan
alan

Under Windows 7 Ultimate I can run CMD.EXE and issue the commands echo %TIME% > "%USERPROFILE%\Application Data"\ALAN_LOST DEL "%USERPROFILE%\Application Data"\ALAN_LOST echo %TIME% > "%APPDATA%"\ALAN_KEPT echo %TIME% >> "%USERPROFILE%\Application Data"\ALAN_LOST TYPE "%USERPROFILE%\Application Data"\ALAN_LOST TYPE "%APPDATA%"\ALAN_KEPT TYPE "%APPDATA%"\ALAN_LOST I can not type the contents of "%USERPROFILE%\Application Data"\ALAN_LOST Everything is lost in a Black Hole when sent to "%USERPROFILE%\Application Data" That Black Hole redirects through a wormhole to "%APPDATA%" I have full access to ALAN_LOST via %APPDATA% even though I cannot see it on the path "%USERPROFILE%\Application Data" This is a typical problem of JUNCTIONS, and ruins the execution of batch scripts. Alan

bg3075
bg3075

One use I could see of value with the purpose of MKLink is cross-compatibility in a Windows/Linux dual-boot computer configuration, as Linux uses "symbolic links" as well. This would make it possible then to read the symbolic links on a drive/partition shared by the Linux and Windows OS'. Does the MKLink tool create symbolic links cross-compatible with Linux?

ctrogers
ctrogers

I've used junctions to good effect to move already installed apps from a hard drive to ssd for much greater performance. First, move your application folder to the ssd. Second, place a junction in the app folder's previous location that directs to the new location. Works like a charm! Just note that you have to be careful as I can see someone uninstalling a secondary hard drive and wondering why apps that should be on the primary drive have stopped working. Also, to make links easier, I use "Link Shell Extension", from http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html

rindi1
rindi1

As I don't like mixing Data with the OS, I move the "\Users\" folders to another partition using MKLink. It works well on Pre-Installed Systems, and it doesn't require me to go through the complicated WAIK and autounattend file. One problem I've found though is that the existing links aren't copied when I copy directories (even freecommander doesn't work here). This means that I first have to check through all the user's directories for existing Links, note what they link to and after the copy recreate them all in the new location. I sure wish there were a way to copy or move existing links, as the users directories have many of them, mainly to keep compatible with old software and OS's, as Windows 7 and Vista use a new folder structure.

Ron_007
Ron_007

links that don't "work" in vista like shortcuts. For example in my Vista Business installation I have C:\ProgramData\Desktop showing up as a light colored shortcut. But when I click on it I get "Location is not Available. C:\.... is not accessible. Access is denied" message box. Or in C:\Users I can access the shortcut to "All Users" folder, but access denied to a shortcut that appears identical to "Default User" folder. When I checked Properties/Security for default user "Everyone" only has inherited "Special Permissions" allowed AND denied rights. Or in C:\Users\User the "Send To" folder shortcut is access denied even though the current user (User) has inherited allow for all rights except "special permissions". In other cases the folder just looks like a light colored (symbolic link?) folder, but still no access. Very annoying, when I can see a folder pointing to a destination I want to get to for the current userid but Vista insists access is denied. I can't seem to figure out the underlying logic that grants and denies access to these "non" folders.

RTHJr
RTHJr

FYI, last I knew, Hardlinks will not cyclically count disk space on files as the OS treats hardlinks as simply a label on the same folder directory or file instead of as separate objects.

public
public

I thought I heard that one of the supposed "improvements" in W7 was that now you could make junction points across a network. Like folder redirection, only MS would let you do it yourself without holding your hand.

eclas
eclas

That clears up a significant difference between the 2!

tchaseb
tchaseb

Symbolic links are just like shortcuts, but hard links are a bit more useful. With hard links, you can move common directories (C:\Users and C:\Program Files) to other partitions or split up where games are saved in Steam. If you have a small SSD where the OS resides, this feature is especially useful.

rindi1
rindi1

Because if they are on the LAN, that won't work. I've tried creating Links to objects on a mapped drive, and it complains that that isn't supported.

alan
alan

I query the paragraph "When you?re finished with any one of these types of symbolic links, you can terminate the link simply by deleting the link. For example, to terminate the one hard link, you?d simply delete the c:\one folder. However, since the link is terminated first and c:\one folder is actually empty, you needn?t be concerned about data loss in the c:\two\three\four folder." There is a warning on http://support.microsoft.com/?kbid=205524 "Never delete a junction point by using Explorer, a del /s command, or other file system utilities that walk recursively into directory trees. These utilities affect the target directory and all subdirectories." Alan

rindi1
rindi1

I don't see why you would need that. You have the Symlinks on your XP partition pointing to the folders on your shared partition, while having other symlinks in your Linux installation pointing to the same folders on your shared partition. So why should you need compatible symlinks, as they are at different locations. Also, Linux Symlinks can work with folders or files located somewhere on the LAN, as long as that location is mounted into the filesystem. This doesn't work with mklink (it complains when you try creating a link to a mapped drive).

RTHJr
RTHJr

I have read some people who know Linux well enough to get Linux to to work on Windows SymLinks; but Windows SymLinks, depending on which implementation of them, tend not to be fully featured as Linux SymLinks, so if you try to get a Windows machine to use a SymLink created by Linux, then it might not work 100% or as expected. But the Vista/7 version is pretty well developed along Linux functions, from what I gather. Having said that, you could just as well setup an external drive and have a dual boot system SymLink to the same files where there is a SymLink on each OS pointing to the same files and folders. That would work OK as long as you have both OSs mounting the data as the same file system and you account for the Linux file permission scheme by installing Linux integration tools on the Windows machine like if you have a Windows system that is POSIX compliant or Microsoft's Services for Unix for newer versions of Windows like XP/Vista/7. Your mileage will vary; but it can be done depending on just how much technical elbow grease you must do to get it all to work.

NickNielsen
NickNielsen

The answer is most likely not. It would be nice, though...

Dogcatcher
Dogcatcher

One of the first things I do on my own systems is to go into Security and take ownership of everything possible in C:. The change seems to eliminate all of the "you can't go there" blockages. There are a few system files that don't change on a mass migration, but that has not been a problem. I have no idea what removing "Trusted Installer" does to security. Whatever the effect, it is a good trade-off for ease of use. I also delete many of the junctions in Documents and Settings and in Users just to reduce clutter.

frank_s
frank_s

It's my understanding that those "light colored" or dimmed shortcuts are there for compatibility with older programs that don't know about newer folder names or locations. For instance from XP to Vista we went from My Documents to Documents. And from Vista to Windows 7 we went back to My Documents.

rindi1
rindi1

In order to be able to access the Links you have to open your explorer (or FreeCommander) as Administrator (right click Windows Explorer, select "Run as Administrator").

Mike Williams
Mike Williams

Simply use Free Commander it knows what to do with Junction points. Free Commander is a superb dual pane replacement for Windows Explorer. It is portable (no install) so you can use it anywhere.

RTHJr
RTHJr

I would image UNC paths on the network should work across a network as per Vista/2008 did. You must have NetBIOS resolution working in one fashion or another which generally means the Network Discovery Service must be running correctly and the Firewall has the correct ports opened up. But if you are talking about across dissimilar networks like to a host on another LAN / Site then that may require a VPN connection with NetBIOS Traversal running or some other direct connection technology such as the Remote Desktop Connection Direct Connection. If NetBIOS Traversal does not work then setting the remote hosts' IP address in the LMHosts file of the local machine might do the trick. Be careful of the Network Location Awareness as well because each remote host connected directly is like connecting to a unique subnet and most Vista and higher computers will default to the Public Network Profile type and lock down a lot of ports on the Firewall. In fact, that was the problem with Vista: it would make any Public connection the defacto Firewall settings for all connections so if you have a Private connection going on, as soon as you fired up something like VMWare with virtual network adapters that defaulted to Public, then NetBIOS communications would stop working because the most stringent Firewall profile of Public was set.

RTHJr
RTHJr

I build images on an external hard drive.

Ron_007
Ron_007

Thanks Mike, that did the trick. Definitely time to retire Explorer. So now can anyone suggest how I can over-ride the shortcut to Explorer and point it to FC? I tried making the change in Properties/shortcut, but Windows only allows or . Funny thing, I used FreeCommander a quite while back, just didn't re-install after an OS refresh. The suggestion that you have to be in an Admin ID for FC to follow links correctly is wrong, I tested. The initial launch of FC after install IS running as an admin because that was what was needed for the install. However, I shut that one down, restarted FC and confirmed in TaskManager that I was running it under a User class ID. It still followed links that explorer did not have access to.

NickNielsen
NickNielsen

More downloads: U3, Portable, Zip, MSI. Takes you here.

tom
tom

What a fabulous little program. I can't believe that I lived this long without it.

Editor's Picks