I stumbled upon this cool Cygwin option that allows you to use native Windows (NTFS) symlinks (like CreateSymbolicLinkW
in the
Win32 API, or mklink
via cmd
shell). Apparently there's a CYGWIN
environment variable that "is used to configure many global settings for
the Cygwin runtime system".
One of those options is winsymlinks:{lnk,native,nativestrict}
.
if set to just
winsymlinks
orwinsymlinks:lnk
, Cygwin creates symlinks as Windows shortcuts with a special header and the R/O attribute set.If set to
winsymlinks:native
orwinsymlinks:nativestrict
, Cygwin creates symlinks as native Windows symlinks on filesystems and OS versions supporting them.The difference between
winsymlinks:native
andwinsymlinks:nativestrict
is this: If the filesystem supports native symlinks and Cygwin fails to create a native symlink for some reason, it will fall back to creating Cygwin default symlinks withwinsymlinks:native
, while withwinsymlinks:nativestrict
thesymlink(2)
system call will immediately fail.For more information on symbolic links, see the section called “Symbolic links”.
So basically, setting the winsymlinks
option to nativestrict
forces Cygwin to use native symlinks!
Normally, when you make symlinks in Cygwin, it creates plain files containing a magic cookie, followed by the path to which the link points to. You can read up on this in the Cygwin documentation.
But with this option, we can create symlinks using ln
and it will create NTFS-style symlinks automatically!
CYGWIN=winsymlinks:nativestrict
ln -sf /source/file /new/path
Cool! No need to open cmd
and manually symlink my files anymore.
Note: You still need Administrator privileges, or must have the SeCreateSymbolicLinkPrivilege
privilege
for this to work.
Perhaps there is something I'm not observing, but your example seems like it works fine:
Could you clarify what's broken?
EDIT: Just wanted to clarify that the above commands were run in a cygwin shell with administrator privileges. Trying the nativestrict setting in a non-privileged shell just gets one an error:
ln: failed to create symbolic link '1': Operation not permitted