Created
March 24, 2018 04:39
-
-
Save karlding/7868aac0c54fe94b7ba0a2061e0a4939 to your computer and use it in GitHub Desktop.
Revisions
-
karlding created this gist
Mar 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ # 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 `mklink` via `cmd` shell). Apparently there's a `CYGWIN` [environment variable](https://cygwin.com/cygwin-ug-net/using-cygwinenv.html) 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` or `winsymlinks:lnk`, Cygwin creates symlinks as Windows shortcuts with a special header and the R/O > attribute set. > > If set to `winsymlinks:native` or `winsymlinks:nativestrict`, Cygwin creates symlinks as native Windows symlinks on filesystems and > OS versions supporting them. > > The difference between `winsymlinks:native` and `winsymlinks: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 with > `winsymlinks:native`, while with `winsymlinks:nativestrict` the `symlink(2)` system call will immediately fail. > > For more information on symbolic links, see > [the section called “Symbolic links”](https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks). 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](https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks). But with this option, we can create symlinks using `ln` and it will create NTFS-style symlinks automatically! ```bash 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](https://security.stackexchange.com/questions/10194/why-do-you-have-to-be-an-admin-to-create-a-symlink-in-windows/10198#10198) for this to work.