Windows

Answers to some common questions about symbolic links

Greg Shultz provides detailed answers to the most common questions he received last week about symbolic links.

In last week's blog, "Be More Efficient and Better Organized with the MKLink Symbolic Link Tool," I provided a brief introduction to the concept of symbolic links and then jumped right into how to use the MKLink command in Microsoft Windows Vista and Windows 7 to create them. After the blog post was published, many folks sent me e-mail or posted questions in the discussion thread asking for a deeper understanding of how symbolic links work within the Windows Vista and 7 operating systems.

Therefore, in this week's edition of the Windows Desktop Report, I'll provide detailed answers to the most common questions I had about symbolic links.

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

What makes symbolic links different from standard shortcuts?

The one question that a lot of folks asked is "What's the difference between a symbolic link and a standard shortcut? They both seem to do the same thing."

Well, standard shortcuts and symbolic links do, in fact, perform a similar function, but there are several differences. To begin with, a symbolic link is a pointer that works at the file-system level as opposed to a shortcut, which is a pointer designed to work within explorer.exe. Since a symbolic link is essentially grafted to the file system, it doesn't have a footprint, so to speak, whereas a shortcut is an actual file on the hard disk.

Take a look at the Properties dialog boxes shown in Figure A. As you can see, the shortcut is an actual file that takes up 4KB of disk space. The symbolic link uses 0 bytes.

Figure A

Shortcuts are files, and symbolic links are part of the file system.

Another difference is that a shortcut is fundamentally a one-shot deal, while a symbolic link has a sustained existence. To see this in action, let's suppose that you use the MKLink command

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

to create the C:\CurrentWork symbolic link folder that points to the path:

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

Then, you use the Create Shortcut wizard to create a shortcut called CurrentWork Shortcut that points to the same path.

If you double-click the CurrentWork Shortcut, you'll see that the shortcut will deliver you to the 9-3 folder, but if you double-click the CurrentWork symbolic link, you'll see the operating system makes it appear that the files actually exist in the CurrentWork folder, as shown in Figure B. The shortcut has done its job and is gone, while the symbolic link continues working.

Figure B

Once a shortcut does its job, it's gone, but a symbolic link continues working.

(This also works from the Save and Open dialog boxes of your applications. The efficiency improvement then comes from the fact that no matter where you are, all you have to remember is the name of the symbolic link.)

If you work from the command prompt, you'll discover that you can access symbolic link folders on the command line, as shown in Figure C. You can't really use a shortcut from the command line.

Figure C

You can access symbolic link folders from the command prompt.

Windows Vista and Windows 7 have built-in symbolic links

Many other folks wrote in to ask why they couldn't use many of Windows Vista's and Windows 7's built-in symbolic links. For example, if you try to access the C:\Documents and Settings symbolic link folder, you'll see an error message like the one shown in Figure D.

Figure D

You'll encounter an Access is Denied error message from some built-in symbolic links.

To begin with, under normal circumstances, you wouldn't even see the operating system's built-in symbolic links, unless you enable the Show Hidden Files, Folders and Drives option on the View tab of the Folder Options dialog box. Unfortunately, many folks do so and thus end up trying to use the built-in symbolic links. However, these symbolic links are not designed for end users; they're designed to provide backward compatibility for older applications.

Windows Vista and Windows 7 have two types of built-in symbolic links designed for backward compatibility called System Junctions and Per-User Junctions.

An example of a System Junction is C:\Documents and Settings. In Windows XP there is an actual folder called Documents and Settings that contains the user profile folders. In Windows Vista and Windows 7, the user profile folders are stored in a folder called C:\Users, as shown in Figure E.

Figure E

User profiles in Windows Vista and Windows 7 are stored in the C:\Users folder.

However, in order to be backward compatible with older applications that are hard-coded to look for and use the C:\Documents and Settings folder in order to access user profiles, both Windows Vista and Windows 7 create a C:\Documents and Settings symbolic link folder that actually points to C:\Users. This allows the older application to think that it is using the C:\Documents and Settings folder when it is actually using the more streamlined C:\Users folder.

An example of a Per-User Junction is C:\Users\Greg Shultz\My Documents. In Windows XP there is an actual folder called My Documents. In Windows Vista and Windows 7, that folder is now called Documents. In order to be backward compatible with older applications that are hard-coded to look for and use the My Documents folder to open and save files, both Windows Vista and Windows 7 create a My Documents symbolic link.

What's your take?

Do these answers give you a better understanding of how symbolic links work in Windows Vista and Windows 7? As always, if you have comments to share or more questions 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.

29 comments
Taehoon Kee
Taehoon Kee

Now I understood what is the difference between junction(from SysInternals) and mklink.

I wonder what is used for specific displaying name for specific directory.

I mean C:\Users directory is displayed as a localized name in explorer but displayed as it is in command prompt in different language version of Windows 7.

Same thing happens in Mac OS X, too. /Users folder is displayed as a localized name in Finder.

What technique is used for this displaying different in localized version of OSes?

Can I use it for my development? or Is it just application specific implementation for localization?

GreyTech
GreyTech

If you link to a network drive share with mklink /d then Windows/File Explorer cannot display thumbnails of pictures or videos but mapping the share to a drive can. e.g. c:\NetDrives>mklink /d pics \\nas\pictures c:\NetDrives>net use z: \\nas\pictures If you use Explorer to look at c:\Netdrives\pics you cannot see thumbnails look at Z:\ and all the thumbnails are there. This seems to be true for Vista/Windows 7/8.

bwechner
bwechner

A nice summary, but I think it would do well, if only for some of us to explore as well: 1) The distinction between symbolic and hard links. A lot of what's described here reminds me of hard links under Unix but I don't trust my memory or recollection of the nuancal differences. 2) How Libraries work in Windows 7 on this level. That is, how are they implemented. Are they Symbolic links? Yet another thing like shortcuts are, or what?

urs.frei
urs.frei

Thanks for the interesting insight - this was new to me. However I was just wondering why not use the Windows 7 libraries where you can also reach folders deep inside your structure (e.g. for your current task)?

Ron_007
Ron_007

Greg: As one of the people who asked one of those questions, thanks for the additional explanation. Could you expand on why MS decided to block user access to System Junctions and Per-User Junctions? If the user is "advanced" enough to turn "display all files", why not let them use these links to familiar locations. I'm guessing there is some sort of security implication (aka MS excuse, "it's a FEATURE, not a BUG!", my reply is "waaall ... It BUGS ME!"), I just can't think of one. (Yes, I am now using FreeCommander as suggested in comments on previous post, but...) OK, I found partial answers to my own question: http://msdn.microsoft.com/en-us/library/bb756982.aspx http://msdn.microsoft.com/en-us/library/bb968829%28VS.85%29.aspx One reason is to prevent backup apps from making multiple copies of same files (ie "My Documents" and "Documents"). Another reason is to prevent (backup) apps from going into endless loops trying to navigate down a directory tree because a symbolic link points back up the tree.

Jaqui
Jaqui

as symlinks have been on the *x systems a long time. they really come in handy when you need to have a specific path for applications, but you are working elsewhere in the file system. Like the dynamic linker, compiler, dynamic loader for building software from sources. They hard code a path to themselves and the libs needed within themselves. so while you are building a cross compiling toolkit for a single use, symlink the path to the / folder and use that for the --prefix= build option to have a stable path for them. standard procedure when compiling GNU/Linux from sources is to build on a partition mounted in /mnt/lfs. the build tools to be disposed of go into /mnt/lfs/tools which path won't exist during latter stages so you symlink /tools to /mnt/lfs/tools then the path is /tools all along, which does work when you have chrooted during the build process. with the to long filename issues that can plague windows systems, a symlink in C:\ to a folder can side step that issue for you.

Mark W. Kaelin
Mark W. Kaelin

Do these answers give you a better understanding of how symbolic links work in Windows Vista and Windows 7? Do you think you will use symbolic links now?

seanferd
seanferd

Are the shriveled remnant of the once up-and-coming WinFS. It's a database, essentially.

gechurch
gechurch

1) My understanding is that yes, junctions/symbolic links are the same as hard links under *nix. 2) Junctions work at the file system level. Go to a junction point, and you will be shown the contents of the junction target. This happens regardless of whether you are using cmd, explorer, Word or a backup program (because juntions work at the file system level, below these apps). Libraries are just a convenient way for lesser-experienced users to find their files. All you do is tell explorer which folders to include in the library (for example, the pictures library includes the current users pictures folder and the all users pictures folders by default). You also specify one of those folders as the default folder to actually save the document to. This all happens at the shell level. Apps that use the standard Windows Open/Save dialog will get it, as will Explorer of course. But it won't help you at the command prompt, or using a ten year old piece of software.

jruby
jruby

I like libraries, but there's two problems with them: 1. I use the command line a LOT, and libraries don't provide any help there. 2. Some applications don't understand the concept of libraries and all the organizing I do in a library is meaningless to them. There has been some change in application support for libraries, but some people may say that's not necessarily a good thing :). Jim

ctrogers
ctrogers

Thanks for your research on the non-user-followable junctions. I've always wondered the same thing.

kama410
kama410

I just looked to see which *nix fan would be the first to post that *nix has had this since, well... since it existed as far as I know. Looks like you were about 45 minutes after the article was posted. *grins* Pretty funny that there should be any debate over it being a useful feature though. (Edited content.)

Ajax4Hire
Ajax4Hire

Anyone mildly familiar with Linux knows about symbolic link (ln -s). This has been a long time coming from Microsoft, the ability to link to a file or directory. I can and have thought of dozens of reasons I need to create a ln -s symbolic link. Apple iTunes does a bastardized version of the symbolic link with its multi-media library database. ln -s/symbolic link is extremely useful in a multi-user environment where you need to give people access but not control. For example a library of music files on a family computer, a link is created in your personal "My Music" directory of the common set of music, no duplication of GB of mp3s; handy on a 3,4,5 user computer.

Former Big Iron Guy
Former Big Iron Guy

Hermann Schinagl has pulled together some outstanding shell extensions for this ans well as some useful utilities using links to reduce multiple copies (think code libraries or games & their extended editions) at http://schinagl.priv.at/nt/ntutils.html From his website the main extension blurb says: Link Shell Extension (LSE) provides for the creation of Hardlinks, Junctions, Volume Mountpoints, and Windows7's Symbolic Links, (herein referred to collectively as Links) a folder cloning process that utilises Hardlinks or Symbolic Links and a copy process taking care of Junctions, Symbolic Links, and Hardlinks. LSE, as its name implies is implemented as a Shell extension and is accessed from Windows Explorer, or similar file/folder managers. The extension allows the user to select one or many files or folders, then using the mouse, complete the creation of the required Links - Hardlinks, Junctions or Symbolic Links or in the case of folders to create Clones consisting of Hard or Symbolic Links. LSE is supported on all Windows versions that support NTFS version 5.0 or later, including Windows XP64 and Windows7. Hardlinks, Junctions and Symbolic Links are NOT supported on FAT file systems, and nor is the Cloning and Smart Copy process supported on FAT file systems. I recommend these and donating to Hermann.

hja
hja

www.softpedia.com/downloadTag/symlink+creator

kirk_augustin
kirk_augustin

I have been using symbolic links on Unix/linux for decades, as well as Windows ports like junctions, and they are a really bad idea. A file system should be a file system, and not a virtual playground for those who are too lazy to use their own methods for maintaining path information. What happens when you do things like do something cyclic, like make a link that points above where the link is embedded? Then directory traversal becomes infinite. What happens then to an operation like prune? You can corrupt the entire file system. There is no need and symbolic links are a bad idea.

CharlieSpencer
CharlieSpencer

Greg, I think you did a great job of explaining the concept and practices, but I don't see a circumstance when I would use this. My file management needs are pretty simple. I'd find constantly resetting link to my current work directory to be more of a nuisance than an advantage.

seanferd
seanferd

I'm sure that I would use them if I had a 7 installation.

kirk_augustin
kirk_augustin

You don't need symbolic links when working from the cmdline, because all you need to do is use aliases.

CharlieSpencer
CharlieSpencer

Scan Greg's article. The word 'new' doesn't appear anywhere. Symbolic links aren't new to Windows; they've been there since XP (possibly NT?). What's new is the introduction of the concept to Windows users, not to the OS. At some point in time I'm sure they were new to you too; you weren't born knowing about them.

Saurondor
Saurondor

You can create a symlink on your home dir called media and point it to a directory in your D drive. If you install a bigger drive later on as E you can point the symlink to E now, but all your apps will still find it in the same path. More so, maybe your audio files stay in D while your movies go to E. So media/audio points to D:/somedir/media/audio while media itself points to E:/somedir/media. Thus you merge the storage capacity of two drives into a single directory path without affecting the applications that depend on that path.

seanferd
seanferd

I was slacking off, apparently. At TR, anyway.

kama410
kama410

For The Win e.g., "And it's Palmetto with end-user-training for the win!"

CharlieSpencer
CharlieSpencer

'FTW'? 'WTF' I've been familiar with long before the web, but 'FTW' I don't know.

CharlieSpencer
CharlieSpencer

Part of my pitch to new employees is that their 'My Documents' folder has been redirected to their H: drive, that the links and shortcuts are two ways of reaching the same storage location. I compare it to a street address and GPS coordinates - two different ways of identifying the same location. I agree with you that many Windows users will find this confusing. They'd have to demonstrate more of an understanding of file organization than I've seen, an understanding that would render crutches like 'libraries' unnecessary.

randytwester
randytwester

I'm not sure if that came with DOS 3 or 5. It was a quick way to shorten a path. Not file-system based, not permanent, not a shortcut. I'm not sure if most end users will ever be ready for symbolic links in Windows. I remember doing restores for users who had deleted all those 'extra' files on the Netware server under "f:\users\bob" that they already had in their "H: Drive".

rindi1
rindi1

Or another situation where symbolic links can be of help, is if have a document, and within that have a hyperlink to another document. Suppose you now move the files or change your directory structure. When you try opening a hyperlinked document from within the master document, it now won't find the original file because it has been moved to some other place. You would now have to edit all your documents that contain such hyperlinks and correct them, or you could use symlinks to point to the new directory locations and simulate the old structure. If you have many such docs this would be much faster.

CharlieSpencer
CharlieSpencer

but I don't have any media files. I've got about 5 gig of vacation photos; that's it.

Editor's Picks