Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

Tip of the Day: mklink: Hard and Symbolic Links in Windows

mklink example
mklink example

If you're a Linux (or even a Mac) command-line person, you're probably already familiar with the concept of filesystem links and the "ln" command. In short:

  • A file is really just a collection of information on your hard disk.
  • A directory entry is just a kind of pointer with a name that points to the information on disk.

So far, so good. Here's the point that most don't realize:

  • There's nothing wrong with having more than one directory entry point to the same information on disk.

In other words, the same file (or folder) can appear to be in two places at once.

What most folks also don't realize is that Windows has the same capability as part of the NTFS filesystem; it's just been under-advertised.

Here's a practical example. I don't like that OneDrive strongly insists on using "c:\users\<loginname>\OneDrive". I much prefer to have my OneDrive folder at the root of my C: drive, as in "C:\OneDrive".

So, in a Windows Command Prompt (run as administrator) I navigated to C:\, and then entered:

mklink /D OneDrive C:\Users\lnote\OneDrive

This created C:\OneDrive, which is a symbolic link1 to C:\Users\lnote\OneDrive. Either can be used interchangeably, almost any time I need to reference the contents of my OneDrive folder. Now it appears at the root of my C:\ drive, alongside my "C:\DropBox" and other similar folders.

Aside from my personal, somewhat anal-retentive need to have these folders at the root of my C:\ drive, you may find the whole concept of file linking, and the mklink utility, a handy addition to your command-line toolbox.

Related Video

Footnotes & References

1: Symbolic and hard links, and more nuances of the linking process, are beyond the scope of this simple tip. The take-away is simply that linking exists :-).

6 comments on “Tip of the Day: mklink: Hard and Symbolic Links in Windows”

  1. Leo
    I’m sure this is good stuff, but as a Windows-only user I know about Folders, Files and Shortcuts.
    Is a link just another name for a shortcut ?
    Regards
    Warren Crawford

    Reply
    • In this context, no … a shortcut and a link are two different things. A link is a property of the file system on the hard disk (formatted NTFS for example – old FAT file systems did not support links). A shortcut is a special construct understood by Windows, regardless of how your hard disk is formatted.

      Reply
  2. The “quick-&-dirty” description is that a link works much like a shortcut — only more VERY MUCH more so: links must be used with real CARE! A link acts as an actual “copy” of the file or directory linked, but with only ONE source. As far the filesystem is concerned, the link IS the file or directory. Among other things, this means that it is possible to DELETE a file or directory by deleting its link (though this is thankfully a tad harder to do than it sounds). This type of functionality is quite powerful, and really useful when it’s needed — the issue being, that it’s almost never needed! In the vast majority of cases, there’s really very little a link can do that an ordinary shortcut can’t. If you insist on using links, research them carefully so that you’ll know what the h*ll you’re doing!

    Reply
    • Thanks for sharing this additional info.
      Knowing that it’s NTFS-specific makes it even more likely that I would use it.
      I will stick with shortcuts for my needs.
      I think shortcuts are also something that are under-understood by most users but extremely useful.
      Cheers!

      Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.