我刚刚在包含多个文件的目录中运行了以下命令,其中一些文件由 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
。