How can I create a junction using cygwin?
Asked Answered
O

2

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 ?

Oscilloscope answered 24/2, 2012 at 15:3 Comment(0)
O
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.

Oscilloscope answered 25/2, 2012 at 16:56 Comment(3)
If you want an actual junction, then you probably should use the /j flag: cmd /c mklink /j name target. Otherwise according to technet.microsoft.com/en-us/library/cc753194.aspx I think you end up with a Windows-style file symbolic link.Unisexual
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 #3649319Blemish
Depending on your exact requirments, this could be a alternative solution worth considering.Vinia
E
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"
Emaciation answered 1/8, 2022 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.