“sudo chmod -rwx”的奇怪行为:不删除组写入权限

Byt*_*der 9 permissions chmod

我只是在包含多个文件的目录中运行以下命令,其中一些由 root 拥有,一些由普通用户拥有。我收到一条奇怪的消息:

$ sudo chmod -rwx *
chmod: example-file: new permissions are ----w----, not ---------
Run Code Online (Sandbox Code Playgroud)

chmod如果文件具有组写权限,为什么会拒绝清除所有权限?这种行为背后的想法是什么?

有没有一种方法可以在一个步骤中强制删除所有权限,而不必sudo chmod g-w *事后执行?

mur*_*uru 13

来自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.
Run Code Online (Sandbox Code Playgroud)

此行为按预期工作,因此不是错误。请参阅此错误报告中的评论 #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
Run Code Online (Sandbox Code Playgroud)

不要做一个懒惰的人。使用a.

  • *“但是 umask 中设置的位不受影响”* - 您能用另一句话解释一下吗? (2认同)