5

This question shows that cygwin’s soft links are somewhat different from ntfs junctions. I’d like cygwin to create a real junction. I thought about running mklink but, hell, there is no mklink.exeApparently, it’s part of the shell command. There I’m stuck.

Any idea how I can do that on a script ?

Community
  • 1
  • 1
qdii
  • 12,505
  • 10
  • 59
  • 116

2 Answers2

13

Found the answer, running cmd.exe /c mklink /j name target did the job. I leave the answer here in case someone runs into the same trouble.

EDIT: Added /j switch as pointed out by Ken Williams in the comments.

qdii
  • 12,505
  • 10
  • 59
  • 116
  • 3
    If you want an actual junction, then you probably should use the `/j` flag: `cmd /c mklink /j name target`. Otherwise according to http://technet.microsoft.com/en-us/library/cc753194.aspx I think you end up with a Windows-style file symbolic link. – Ken Williams Sep 12 '13 at 15:04
  • 1
    The recent windows native symlinks have advantages over the more limited junction points, which aren't treated correctly by some software (e.g., anything running on the java jvm, for example). See http://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7 – philwalk Nov 11 '14 at 19:06
  • Depending on your exact requirments, [this](https://stackoverflow.com/questions/3648819/how-to-make-a-symbolic-link-with-cygwin-in-windows-7#18660841) could be a alternative solution worth considering. – user1934428 Dec 15 '22 at 16:05
1

Seems ln (from coreutils) and winln (from cygutils-extra) are unable to create a junction; they only creates hard or symlinks.

The only solution is to use cmd:

cmd.exe /c mklink /j $TARGET $SOURCE

or PowerShell:

powershell.exe New-Item -ItemType Junction -Path "Link" -Target "Target"
gavenkoa
  • 45,285
  • 19
  • 251
  • 303