10

I've no problem in creating junctions and symbolic links through mklink, but can't create hard link using this command. It returns "Access denied", have tried on both Windows 7 and 8.1 on different machines, cmd started with administrative privileges.

D:\>mklink /d /h dirA dirB

Of course dirB exists. Is there something I should do to run this command without error?

2
  • 4
    If /d makes a symlink, and /h makes a hardlink instead of a symlink, how do you suppose to use them in the same command? At least, reading the current documentation
    – jiggunjer
    Dec 22, 2016 at 14:15
  • re-read the documentation, at least four time: /d and /h option are not compatible;. /d means create a directory junction point (a microsoft construct of ntfs, more closly relted to soft/symbolic links in *nix), while /h means create a hard link, not a soft link. a hard AND soft/symbolic link is irrational as the idea as as polar opposites as good vs evil.
    – C. M.
    Jan 1 at 15:54

3 Answers 3

11

I'm pretty sure you can't create a hard link to a folder, only files. Symbolic links /D and junctions /J would work for folders though.

Also when creating hard links, keep in mind that you cannot create links between 2 different drives (even on the same physical hard drive).

A short explanation from another SU answer:

A hard link is a file system feature that cannot cross a file system boundary. You can't hard link files on C: to D: because they are separate file systems. They might each contain the same type of file system (eg. NTFS) but they are separate file systems.

3
  • Yes, thank you. You're right, it isn't working on directories, but hope it will be provided in the future as it has really important features.
    – Jarek
    Apr 26, 2014 at 22:17
  • it's named 'partition', a part of a disc
    – Yura
    Oct 8, 2023 at 18:31
  • @jarek: it likely will never be added -- the technical issues and problems it create would require extreme amounts of logic (we'd need an AI greater than the Matrix to figure it out) and processing power (we'd need to network and dedicate the world's computers all as one to compute it in hours instead of years). a comment lacks space to explain; search Google to understand the problems and issues and why their are no easily feasible solutions.
    – C. M.
    Jan 1 at 15:45
5

As David commented in reply to Braden, Junctions may not technically be "hard folder links," but I think one could say that "/J is harder than /D"

Case in point is that if you mklink /D "..\link_dir" "existing_dir", you will not be able to cd into "link_dir". However, you can cd if you use /J instead.

4

No you CAN make a hard link to a folder/directory. It's called a junction. mklink /J

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365006(v=vs.85).aspx http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html

Also, mklink /D creates a directory symbolic link, not a hard link. In practice, symbolic links are "fancy shortcuts" to files and folders, while hard links are sort of like a "file sync" for files only, where the "shortcut" is a "twin" of the target file; make changes to one, and you make changes to both...but in reality there is actually only one file physically on the drive, so if the target file is 500MB in size, only 500MB are being used. JUNCTIONS are hard links for folders and function the same as hard links.

5
  • 1
    Rubbish. A junction is not a hard link. It is something different (a soft link). From the link in your answer "A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories, and a junction can link directories located on different local volumes on the same computer."
    – DavidPostill
    May 10, 2016 at 20:13
  • 2
    Well I have used this numerous times and it works just fine as a solid link that syncs changes to the involved files. It may not be the same thing as a "hard link" but it does the job. There does not seem to be a lot of solid information on how links and junctions and such work in NTFS. Does anyone know a website or book that provides good information on NTFS? Feb 27, 2017 at 0:57
  • @BradenDodge There's really a lot of information available: msdn.microsoft.com/en-gb/library/dn466522(v=ws.11).aspx#United Kingdom (English) ntfs.com en.wikipedia.org/wiki/NTFS msdn.microsoft.com/de-de/library/windows/desktop/… Nov 20, 2017 at 18:13
  • 2
    Yes, and everything I read there indicates that Junction Ponts function in the EXACT same way as hard links. The only difference is a "hard link" is for files and a "directory junction" is for directories. It's purely semantics. Maybe I am missing something, if you are aware of something different please let me know. Jan 30, 2018 at 0:12
  • 1
    A bit late, but a major difference is if you delete the Source folder a Junction ceases to function, whereas a hardlink would continue to provide access to the files that were originally in Source.
    – jiggunjer
    Jan 22, 2023 at 14:57

You must log in to answer this question.

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