How to make Cygwin use native symlinks
I stumbled upon this cool Cygwin option that allows you to use native Windows (NTFS) symlinks (like
CreateSymbolicLinkW in the
Win32 API, or
cmd shell). Apparently there's a
environment variable that "is used to configure many global settings for
the Cygwin runtime system".
One of those options is
if set to just
winsymlinks:lnk, Cygwin creates symlinks as Windows shortcuts with a special header and the R/O attribute set.
If set to
winsymlinks:nativestrict, Cygwin creates symlinks as native Windows symlinks on filesystems and OS versions supporting them.
The difference between
winsymlinks:nativestrictis 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 with
winsymlinks:native, while with
symlink(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
for this to work.