"directory junction" vs "directory symbolic link"?
Solution 1
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.
Solution 2
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.
**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)
From SS64 page on MKLink
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.
Solution 3
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
Related videos on Youtube
Comments
-
Pacerier almost 2 years
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.Isn't a directory junction the exact same thing as a directory symbolic link?
What's the difference between
mklink /D f1 f2
andmklink /J f1 f2
?Since a "directory" is actually just a file, what would be the difference between a directory symbolic link and a file symbolic link?
-
Admin over 3 yearsWarning: 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.
-
Harry Johnston almost 13 yearsJust 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.
-
Pacerier almost 13 yearsSry I find the second paragraph quite ambiguous. If I create a symbolic link
testlink
on the client, which links to thec:\test
folder on the server, doesn'ttestlink
(symbolic link) also allow me to see the contents of theC:\test
folder on the server? -
Pacerier almost 13 years@MatthewSteeples do you mean that if I create a symbolic link
C:\testlink
(which points toC:\test
on my computer) and someone remote access my computer and clicks onC:\testlink
, it would resolve to theC:\test
on HIS computer, Whereas if I create a directory junctionC:\testlink
(which points toC:\test
on my computer), and someone remote access my computer and clicks onC:\testlink
) it would lead him to theC:\test
on my computer? Or did I get it the wrong way round? -
Matthew Steeples almost 13 years@Pacerier that's right. You've got it the right way round in your example
-
Harry Johnston almost 13 yearsI've edited my answer to expand on the example, hopefully it is clearer now.
-
Pacerier almost 13 years@Matthew ic, so that means that symbolic links are useless
-
Matthew Steeples almost 13 years@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
-
Pacerier over 12 years@MatthewSteeples but couldn't we create a directory junction
C:\MyNetworkShare
which points to\\Alice\Share
as well? -
Harry Johnston over 12 years@Pacerier, no, junction points have to be local.
-
David I. McIntosh about 10 yearsAlso: suppose a machine has two network cards, and so is known on the network by two different names. (E.g. a subnet of high-end calculation servers, each with one 100MB card on the larger, main network, and each with 40GB cards on a smaller network connecting them to the file server for inter-calc cummunication). Consider a junction on the file-server Svr: G:\jnctn -> G:\trgt. If the server is known as SvrA on the 100MB network and SrvB on the 40GB network, and G:\ is shared as Shr, then \\SvrA\shr\jnctn and \\SvrB\shr\jnctn both resolve to G:\trgt on the server.
-
David I. McIntosh about 10 yearsAnd the key thing about this is: they resolve on the same network as the original access. That is, \\SvrA\shr\jnctn resolves, in effect, to \\SvrA\shr\trgt, i.e. resolves on the 100MB network, and \\SrvB\shr\jnctn resolves to \\Svrb\shr\trgt, i.e. resolves on the 40GB network. If you were to create a symbolic link that still works for external access, you would need to link as G:\jnctn -> \\SrvA\shr\tgt or \\SrvB\shr\tgt, and so you are deciding the network access in the link itself. This may be desirable or may be exactly what you don't want!
-
Mallow almost 10 yearsI'm confused about the junction link above. Is the source of that folder on Bob's computer?
-
user193130 almost 10 years@Mallow I think everything is on Alice's computer. Bob is merely a client accessing Alice
-
ahnbizcad almost 9 yearsRegard writing style, when comparing two things, it's clearer to unfamiliar people to explicitly state which goes with which. The following is confusing: "One is foo foo, and the other is bar bar"... (so... which one?)
-
Harry Johnston almost 9 years@ahnbizcad: I really don't think it necessary to spell out explicitly that the directory symbolic link represents a directory and the file symbolic link represents a file. It's hardly likely to be the other way around!
-
Daan almost 9 years@Harry Johnston, can you say more about " junctions are processed at the server and directory symbolic links are processed at the client" or where you got this from?
-
Harry Johnston almost 9 years@Daan: the fact that symbolic links cross SMB is documented in What's new in SMB?. I don't know of any documentation that explicitly states that junction points don't, but it is inherent in the way they are implemented and I did find Create the SYSVOL Root and Staging Areas Junction Point which otherwise wouldn't work. (Mostly though, it's just experience.)
-
Daan almost 9 years@Harry Johnston, the reason I asked is because I had a problem with using junctions and symbolic links in my webserver, I posted the question here: serverfault.com/questions/722381/…
-
barlop about 8 yearswas there something else about safety or not wit deleting them?
-
Nux almost 8 yearsThat 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 tod:\_tmp
and all its subfolders BUT he will still not be able to opend:\_tmp\data-link
. -
apraetor almost 8 yearsThat is because when a symbolic link gets evaluated client-side it would be pointing to d:\_tmp\data on the client, not the server.
-
CMCDragonkai over 7 yearsIt's possible to create a file symlink to a directory though. This still works in Cygwin, however if you don't explicitly set it to a
/D
, then apps like Windows explorer doesn't realise it's a directory symlink and show it as a directory and allow traversal. -
Jon Coombs over 7 yearsI 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.
-
barlop almost 7 yearsapparently win xp and prior had a danger issue re deleting junctions. cects.com/… Safest thing is a suggestion here that'd apply to symbolic links or junctions or whatever, superuser.com/questions/167076/how-can-i-delete-a-symbolic-link add an underscore or rename, the actual non-link target directory, then the link or junction thing, shows as empty and delete it with eg rmdir or
-
Harry Johnston almost 7 years@barlop, AFAIK, you can always delete a junction or directory symbolic link with rmdir, you don't need to make it appear to be empty first.
-
barlop almost 7 years@HarryJohnston I didn't say you had to. My point is that it's safer to temporarily rename the target. so that a)one is not deleting the wrong one(the target when one means to delete the junction and only the junction), and b)that link documents that XP and win2K3 and prior, had an issue where deleting a junction deleted the target directory itself too. So it's safer from the perspective of behaviour of prior Win OSs and human error.
-
barlop almost 7 years@HarryJohnston Also do you know of a quick way to test if a directory is a link(unless one made a batch file with a command like this) stackoverflow.com/questions/18883892/… so without a quick easy check, I suppose if one can quickly check then one can do it safely (putting aside the issue with previous OSs like XP and Win2K3 and prior)
-
Harry Johnston almost 7 years@barlop,
rmdir
should be safe, I'm pretty sure it only ever deletes the junction, not the target. It certainly won't delete any content unless you specify/s
. I would normally just usedir
(on the parent directory) to see whether something is a junction point. In some cases that might not be convenient, I suppose. -
barlop almost 7 years@HarryJohnston ah yes you're right. good idea re rmdir(without /s), and rm, and re dir on the parent.. I see even dir c:\blahsymboliclink will just show the symbolic link.. so it's not like with dir c:\windows which does dir c:\windows*.* dir c:\blahsymboliclink will show whether it's a symbolic link or not. dir c:\blahsymbolic link is a bit like dir c:\windo* or
ls -ld blah
it won't list the contents of the symbolic link directory itself unless you dod ...*.* or were within it. -
1000Gbps almost 6 yearsAnyone tested the processing speed of Junctions vs Symbolic Links?
-
GordonM almost 6 yearsThe pros/cons chart was extremely helpful, thank you!
-
Luke about 5 years
Complex talk hurts brain -- I like charts
I love this sentence, and the chart too.