为Cygwin启用本机NTFS符号链接 [英] Enable native NTFS symbolic links for Cygwin

查看:389
本文介绍了为Cygwin启用本机NTFS符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近NTFS和Windows实现符号链接:

Recent NTFS and Windows implement symlinks:


  • NTFS连接点可以用作目录符号链接自NTFS 3.0(Windows 2000)使用 linkd 工具。

  • NTFS符号链接也可以用作符号链接文件和目录),因为Windows Vista使用 mklink 工具。

  • NTFS junction point can be used as directory symlink since NTFS 3.0 (Windows 2000) using linkd or junction tools.
  • NTFS symbolic link can also be used as symlink (for both file and directory) since Windows Vista using mklink tool.

Cygwin 1.7(安装在Windows 7上), ln -s 在Cygwin上创建一个文本文件。

But on Cygwin 1.7 (installed on Windows 7), ln -s creates a text file.



on Cygwin:

$ ln -s -v target mylink
`mylink' -> `target'

$ cat mylink
!<symlink>ÿþt a r g e t 

可以告诉Cygwing使用 NTFS连接点 NTFS符号链接

Is it possible to tell Cygwing to use NTFS junction point or NTFS symbolic link?

其他问题:这是否在MinGW上可用?

推荐答案

-------短回答 -



定义环境变量:

------- Short answer -------

Define environment variable:

CYGWIN=winsymlinks:nativestrict

正如 mwm ,您可能还需要运行 bash 作为管理员。

As pointed out by mwm you may also have to run bash as Administrator.

默认情况下 Cygwin 创建文本文件作为Windows符号链接缺陷的解决方法。
这些文件实际上不是符号链接
几乎所有Windows程序都不将这些文件视为符号链接。

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.

最近NTFS和Windows实现符号链接:

Recent NTFS and Windows implement symlinks:


  • NTFS连接点可以用作目录符号链接
    ,因为NTFS 3.0(Windows 2000)使用 linkd code> junction 工具。

  • NTFS符号链接也可以用作符号链接
    (对于文件和目录),因为Windows Vista使用 mklink 工具。
  • NTFS junction point can be used as directory symlink since NTFS 3.0 (Windows 2000) using linkd or junction tools.
  • NTFS symbolic link can also be used as symlink (for both file and directory) since Windows Vista using mklink tool.

简化了 Cygwin文档


符号链接



[...]

Symbolic links

[...]

Cygwin以多种不同的方式创建符号链接:

Cygwin creates symbolic links potentially in multiple different ways:


  • 默认的符号链接是包含魔术cookie的纯文件
    ,后面是链接所指向的路径。 [...]

  • The default symlinks are plain files containing a magic cookie followed by the path to which the link points. [...]

快捷方式样式符号链接是Windows .lnk [...]
如果环境变量CYGWIN [...]设置为包含
字符串 winsymlinks winsymlinks:lnk 。 [...]

The shortcut style symlinks are Windows .lnk [...] created if the environment variable CYGWIN [...] is set to contain the string winsymlinks or winsymlinks:lnk. [...]

本地Windows符号链接仅在Windows Vista / 2008及更高版本
上创建,并且仅在支持重分析点的文件系统上创建。
由于他们的奇怪的限制和行为,他们只创建
如果用户明确地请求创建它们。
这是通过设置环境变量CYGWIN
来包含字符串 winsymlinks:native winsymlinks:nativestrict
[...]

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 or winsymlinks:nativestrict. [...]

在NFS文件系统上,Cygwin总是创建真正的NFS符号链接。

On the NFS filesystem, Cygwin always creates real NFS symlinks.



配置Cygwin



Cygwin用户指南显示变量 CYGWIN 和选项 winsymlinks


CYGWIN 环境变量用于配置许多全局设置[...]。
它包含下面列出的选项,用空格分隔。 [...]

The CYGWIN environment variable is used to configure many global settings [...]. It contains the options listed below, separated by blank characters. [...]


  • [...] li ...
  • [...]
  • winsymlinks:{lnk,native,nativestrict}
    -
    如果设置为 winsymlinks winsymlinks:lnk ,Cygwin创建符号链接
    作为具有特殊头和R / O属性集的Windows快捷方式。
  • [...]
  • [...]
  • [...]
  • [...]
  • winsymlinks:{lnk,native,nativestrict} - if set to just winsymlinks or winsymlinks:lnk, Cygwin creates symlinks as Windows shortcuts with a special headerand the R/O attribute set.

如果设置为 winsymlinks:native winsymlinks:nativestrict
Cygwin创建符号链接作为文件系统上的本地Windows符号链接
和操作系统版本支持他们。如果操作系统已知不支持
本地符号链接(Windows XP,Windows Server 2003),则每个会话会产生一个警告消息

If set to winsymlinks:native or winsymlinks: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.

winsymlinks:native
winsymlinks:nativestrict 之间的区别是:如果文件系统支持native
符号链接和Cygwin由于某种原因无法创建本地符号链接
它会回到创建Cygwin默认符号链接
winsymlinks:native ,而 winsymlinks:nativestrict
symlink(2)系统调用将立即失败。 >

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.



CYGWIN = winsymlinks:native 很好



在Cygwin上:

CYGWIN=winsymlinks:native is fine

on Cygwin:

$ export CYGWIN="winsymlinks:native"
$ ln -s -v target mylink
`mylink' -> `target'
$ echo content > target

在MinGW上:

$ cat mylink
content



CYGWIN = winsymlinks:nativestrict 更多严格



nativestrict

CYGWIN=winsymlinks:nativestrict is more strict

nativestrict requires the target exists before the symlink creation.

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'

注意:只有管理员才能创建本机NT symlinks
所以在Windows UAC下,Cygwin终端模拟器(mintty)
应该使用提升的权限运行
(右键单击快捷方式并选择以管理员身份运行
或设置mintty快捷方式属性,高级→以管理员身份运行)。

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).

特别感谢 Guria 幽灵的贡献。

Special thanks to Guria and Spooky for their contributions.

这篇关于为Cygwin启用本机NTFS符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆