Recent NTFS and Windows implement symlinks:
linkd
or junction
tools.mklink
tool.But on Cygwin 1.7 (installed on Windows 7), ln -s
creates a text file.
on Cygwin:
$ ln -s -v target mylink `mylink' -> `target'
on MinGW (or your favorite editor):
$ cat mylink !<symlink>ÿþt a r g e t
Is it possible to tell Cygwing to use NTFS junction point or NTFS symbolic link?
other question: Is this available on MinGW?
Symlinks, or symbolic links, are “virtual” files or folders which reference a physical file or folder located elsewhere, and are an important feature built in to many operating systems, including Linux and Windows. The Windows' NTFS file system has supported symlinks since Windows Vista.
Windows 11, 10, 8, 7, and Vista all support symbolic links — also known as symlinks — that point to a file or folder on your system. You can create them using the Command Prompt or a third-party tool called Link Shell Extension.
OneFS allows SMB2 clients to access symbolic links in a seamless manner. In an SMB share, a symbolic link (also known as a symlink or soft link) is a type of file that contains a path to a target file or directory.
Define environment variable:
CYGWIN=winsymlinks:nativestrict
As pointed out by mwm you may also have to run bash as Administrator.
By default Cygwin creates text files as workaround for Windows symlink flaw. These files are not really symlinks. Almost all Windows programs do not considers these files as symlinks.
Recent NTFS and Windows implement symlinks:
linkd
or junction
tools.mklink
tool.Simplified extract of the Cygwin documentation:
Symbolic links
[...]
Cygwin creates symbolic links potentially in multiple different ways:
The default symlinks are plain files containing a magic cookie followed by the path to which the link points. [...]
The shortcut style symlinks are Windows
.lnk
[...] created if the environment variable CYGWIN [...] is set to contain the stringwinsymlinks
orwinsymlinks:lnk
. [...]Native Windows symlinks are only created on Windows Vista/2008 and later, and only on filesystems supporting reparse points. Due to to their weird restrictions and behaviour, they are only created if the user explicitely requests creating them. This is done by setting the environment variable CYGWIN to contain the string
winsymlinks:native
orwinsymlinks:nativestrict
. [...]On the NFS filesystem, Cygwin always creates real NFS symlinks.
Cygwin User's Guide presents variable CYGWIN
and option winsymlinks
:
The
CYGWIN
environment variable is used to configure many global settings [...]. It contains the options listed below, separated by blank characters. [...]
- [...]
- [...]
- [...]
- [...]
winsymlinks:{lnk,native,nativestrict}
- if set to justwinsymlinks
orwinsymlinks:lnk
, Cygwin creates symlinks as Windows shortcuts with a special headerand 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. If the OS is known not to support native symlinks (Windows XP, Windows Server 2003), a warning message is produced once per session.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.
CYGWIN=winsymlinks:native
on Cygwin:
$ export CYGWIN="winsymlinks:native" $ ln -s -v target mylink `mylink' -> `target' $ echo content > target
on MinGW:
$ cat mylink content
People using both Windows and Cygwin programs may have issues when a symlink is created as a dummy file (Cygwin fallback when target is missing)...
CYGWIN=winsymlinks:nativestrict
on Cygwin:
$ export CYGWIN="winsymlinks:nativestrict" $ rm -f a b $ ln -sv a b ln: failed to create symbolic link `b': No such file or directory $ touch b $ ln -sv a b ln: failed to create symbolic link `b': File exists $ rm b $ touch a $ ln -sv a b `b' -> `a'
Because nativestrict
requires the target exists before the symlink creation, some commands/scripts may fail when creating a link.
Note: Only administrators have the ability to create native NT symlinks so under Windows UAC, the Cygwin terminal emulator (mintty) should be run with elevated privileges (right-click the shortcut and choose Run as Administrator or set the mintty shortcut property, Advanced → Run as Administrator).
Special thanks to Guria and Spooky for their contributions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With