cygwin 的 chmod 工作正常,但不起作用

boa*_*der 7 windows-7 cygwin bash permissions chmod

我的 Cygwin 安装行为异常:chmod不起作用。

[09:45 Administrator@DellIns14 ~] > ls -ls /usr/bin/chmod
64K -rwxr-xr-x 1 Administrator None 38K Feb  6  2012 /usr/bin/chmod

[09:47 Administrator@DellIns14 ~] > rm /tmp/example.sh
rm: remove regular empty file `/tmp/example.sh'? y
[09:48 Administrator@DellIns14 ~] > touch /tmp/example.sh
[09:48 Administrator@DellIns14 ~] > ls -ls /tmp/example.sh
0 -rw-r--r-- 1 Administrator None 0 Jul  8 09:48 /tmp/example.sh
[09:48 Administrator@DellIns14 ~] > chmod -v +x /tmp/example.sh
mode of `/tmp/example.sh' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x)
[09:48 Administrator@DellIns14 ~] > ls -ls /tmp/example.sh
0 -rw-r--r-- 1 Administrator None 0 Jul  8 09:48 /tmp/example.sh
[09:48 Administrator@DellIns14 ~] >
Run Code Online (Sandbox Code Playgroud)

请注意,该目录是可写的,因为该文件已创建。

当我从Windows 的角度查看这个目录时,它被报告为只读(即使我将其更改为读写,它也会恢复为只读)。
屏幕截图在cygwin 的 /tmp 在 windows 中是只读的,不能更改为读写

你能建议如何调试/解决吗?


环境:
Windows 7、Cygwin 1.7.29(0.272/5/3) i686

小智 7

这个答案的荣誉/sf/ask/1801102901/内容粘贴在下面


您可能在 Windows 上使用 NTFS 或 FAT32,而这些文件系统不支持可执行权限。相反,cygwin 查看文件名和内容以确定它是否可执行

如果文件名以 .bat、.com 或 .exe 结尾,或者其内容以 #! 开头,则文件被视为可执行文件。

所以你应该确保bash文件以shebang开头。然后,您应该能够只执行该文件,而忽略ls.


小智 2

我发现这个答案很有帮助。

除了控制所有者、组和其他访问的正常 POSIX 权限之外,Cygwin 中的文件权限也可能受到 Windows ACL 的影响。

对于您的情况,请尝试

ls -l /tmp/example.sh
getfacl /tmp/example.sh
setfacl -b /tmp/example.sh
ls -l /tmp/example.sh
chmod -v +x /tmp/example.sh
ls -l /tmp/example.sh
Run Code Online (Sandbox Code Playgroud)