![‘sudo chmod -rwx’ 的奇怪行为:不会删除组写权限](https://linux22.com/image/1086691/%E2%80%98sudo%20chmod%20-rwx%E2%80%99%20%E7%9A%84%E5%A5%87%E6%80%AA%E8%A1%8C%E4%B8%BA%EF%BC%9A%E4%B8%8D%E4%BC%9A%E5%88%A0%E9%99%A4%E7%BB%84%E5%86%99%E6%9D%83%E9%99%90.png)
我刚刚在包含多个文件的目录中运行了以下命令,其中一些文件由 root 用户拥有,一些文件由普通用户拥有。我收到了一条奇怪的消息:
$ sudo chmod -rwx *
chmod: example-file: new permissions are ----w----, not ---------
如果文件具有组写入权限,为什么拒绝chmod
清除所有权限?这种行为背后的想法是什么?
有没有办法可以强制删除所有权限,而无需sudo chmod g-w *
事后执行?
答案1
从man chmod
(重点是我的):
A combination of the letters ugoa controls which users' access to the
file will be changed: the user who owns it (u), other users in the
file's group (g), other users not in the file's group (o), or all users
(a). If none of these are given, the effect is as if a were given, but
bits that are set in the umask are not affected.
此行为按预期工作,因此不是错误。请参阅评论 #4 和 #5此错误报告。
$ touch 1; ll
total 0
-rw-rw-r-- 1 muru muru 0 Jan 9 03:17 1
$ chmod -rwx *; ll
total 0
---------- 1 muru muru 0 Jan 9 03:17 1
$ umask
002
$ umask 072; chmod ug+rw *
$ chmod -rwx *
chmod: 1: new permissions are ---rw----, not ---------
$ chmod a-rwx *; ll
total 0
---------- 1 muru muru 0 Jan 9 03:17 1
别懒了。使用a
。