564

In the context of NTFS:

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.

  1. Isn't a directory junction the exact same thing as a directory symbolic link?

    What's the difference between mklink /D f1 f2 and mklink /J f1 f2 ?

  2. Since a "directory" is actually just a file, what would be the difference between a directory symbolic link and a file symbolic link?

3
  • 4
    Related: superuser.com/q/347930/24500
    – surfasb
    Dec 29, 2011 at 13:05
  • 9
    Warning: Windows 10 has serious holes regarding symlinks: e.g. deleting the junction is safe but just moving it to some dest empties the original directory! It leaves the junction at its initial location, and at the dest there will be an independent folder with the original contents. This can however be undone. Now, symlinks don't have this problem, (moving the symlink will carry its target). Still, moving it to another volume will make an empty independent folder and undoing this will move the independent folder at the initial symlink location. These are just a few behaviors.
    – mireazma
    Jan 13, 2021 at 22:19
  • @mireazma on Jan 13, 2021 - Tried it and could not reproduce. This seems to be fixed in Windows 10 21H2 [Version 10.0.19044.2846], possibly earlier.
    – Lumi
    Apr 20, 2023 at 13:56

3 Answers 3

507

A junction is definitely not the same thing as a directory symbolic link, although they behave similarly. The main difference is that, if you are looking at a remote server, junctions are processed at the server and directory symbolic links are processed at the client. Also see Matthew's comment on the fact that this means symbolic links on the local file system can point to remote file systems.

Suppose that on a machine named Alice you were to put a junction point c:\myjp and a directory symbolic link c:\mysymlink, both pointing to c:\targetfolder. While you're using Alice you won't notice much difference between them. But if you're using another machine named Bob, then the junction point

\\Alice\c$\myjp will point to \\Alice\c$\targetfolder

but the symbolic link

\\Alice\c$\mysymlink will point to \\Bob\c$\targetfolder

(Caveat: by default, the system doesn't follow symlinks on remote volumes, so in most cases the second example will actually result in either "File Not Found" or "The symbolic link cannot be followed because its type is disabled.")

The difference between a directory symbolic link and a file symbolic link is simply that one represents a directory and one represents a file. Since the target of the link doesn't need to exist when the link is created, the file system needs to know whether to tell applications that it is a directory or not.

It should also be noted that creating a symbolic link requires special privilege (by default, only available to elevated processes) whereas creating a junction only requires access to the file system.

28
  • 24
    Just to be clear: there may well be other subtler functional differences between directory junctions and directory symbolic links. The remote vs. local thing is just the most obvious from a user (as opposed to a developer) perspective. Oct 5, 2011 at 4:02
  • 18
    @MatthewSteeples do you mean that if I create a symbolic link C:\testlink (which points to C:\test on my computer) and someone remote access my computer and clicks on C:\testlink, it would resolve to the C:\test on HIS computer, Whereas if I create a directory junction C:\testlink (which points to C:\test on my computer), and someone remote access my computer and clicks on C:\testlink) it would lead him to the C:\test on my computer? Or did I get it the wrong way round?
    – Pacerier
    Oct 5, 2011 at 8:19
  • 11
    @Pacerier in this context yes, but symbolic links allow you to have a folder on your computer that points to a network share (because they're resolved client side). Eg C:\MyNetworkShare could actually point to \\Alice\Share Oct 6, 2011 at 14:57
  • 9
    @MatthewSteeples but couldn't we create a directory junction C:\MyNetworkShare which points to \\Alice\Share as well?
    – Pacerier
    Oct 7, 2011 at 10:44
  • 13
    @Pacerier, no, junction points have to be local. Oct 8, 2011 at 0:05
175

Symbolic links have more functionality, while junctions almost seem to be a legacy feature because of their limitations, but the security implications of these limitations are specifically why a junction might be preferred over a symbolic link. Remote targeting makes symbolic links more functional, but also raises their security profile, while junctions might be considered safer because they are constrained to local paths. So, if you want a local link and can live with an absolute path, you're probably better off with a junction; otherwise, consider a symbolic link for its added abilities.

Comparison between Junctions and Symbolic Links

*The statement of difference in speed/complexity comes from an unverified statement in the Wikipedia entry on NTFS reparse points (a good read).


Other NTFS Link Comparisons

Here are some other comparisons on the topic, but these can be misleading when considering junctions because they don't list the benefits I list above.

Taken from here (a good introductory read)

NTFS Link Comparison

From SS64 page on MKLink

SS64 page on MKLink comparison table


Comments about Terminology

Junctions are Symbolic Links

Junctions and Symbolic links are really doing the same thing in the same way (reparse points), aside from the aforementioned differences in how they're processed. In fact, technically, a Junction is a symbolic link, and sometimes documentation might call a Junction a symbolic link, as is the case here. So, that's just something to be aware of regarding terminology.

NTFS

Even though the OP specifies this, it's worth pointing out that "symbolic link" is a very general term that is not specific to NTFS. So, to be specific, this comparison is about NTFS Junctions vs. NTFS Symbolic Links.

3
  • 8
    Anyone tested the processing speed of Junctions vs Symbolic Links?
    – 1000Gbps
    Sep 1, 2018 at 13:59
  • 3
    The pros/cons chart was extremely helpful, thank you!
    – GordonM
    Sep 20, 2018 at 15:52
  • For what it's worth, links were supported in NTFS right from the beginning i.e. NT 3.1, but NT didn't have a command for handling them! You could get this from a powertoys-like pack that could manipulate them, or perhaps needed outright a third party tool, but the filesystem did support it natively.
    – Barleyman
    Mar 3 at 17:04
79

Complex talk hurts brain -- I like charts:

Assume any MyLink is a symbolic link and any MyJunc is a junction pointing at Target as created.

e.g.

mklink /D MyLink C:\T_Dir for creating a symbolic link to the target directory

mklink /J MyJunc C:\T_Dir for creating a directory junction to the target directory

Where syntax is mklink [/J,/D] [link path] [target path] as typed on local machine


 link path    |   target path   |         When accessed ..
              |                 |  (locally)    |    (remotely)
              |                 |               |
C:\MyLink     |   C:\T_Dir      |  C:\T_Dir     |  [leads back to local]
C:\MyJunc     |   C:\T_Dir      |  C:\T_Dir     |  [leads to remote]
              |                 |
\\Svr\MyLink  |   C:\T_Dir      |   C:\T_Dir    |  [leads back to local]
\\Svr\MyJunc  |   C:\T_Dir      |  *** Must create and point local ***
              |                 |
C:\MyLink     |  \\Sv2\T_Dir    |  \\Sv2\T_Dir  |   Error*1
C:\MyJunc     |  \\Sv2\T_Dir    |  *** Error - Must point local ***
              |                 |
\\Svr\MyLink  |  \\Sv2\T_Dir    |  Error*1
\\Svr\MyJunc  |  \\Sv2\T_Dir    |  *** Must create link using target device ***

Error*1 - If you unblocked access to remote symbolic links on your local machine, then this would work .. but only on the local machine where it's unblocked

4
  • 3
    That is so weird. Even relative symbolic links don't work remotely. E.g. I create a directory d:\_tmp\data. Create link like so: d:\_tmp>mklink /d data-link data. Remote user has full access to d:\_tmp and all its subfolders BUT he will still not be able to open d:\_tmp\data-link.
    – Nux
    Aug 19, 2016 at 11:18
  • 5
    That is because when a symbolic link gets evaluated client-side it would be pointing to d:\_tmp\data on the client, not the server.
    – apraetor
    Sep 24, 2016 at 12:13
  • I think the reason why it's weird is clear. But I agree with @Nux that it IS weird, at least in the case of relative symlinks.
    – Jon Coombs
    Mar 21, 2017 at 22:36
  • 5
    Complex talk hurts brain -- I like charts I love this sentence, and the chart too.
    – Luke
    Jun 24, 2019 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .