如何使用 CHMOD 获得“drwx---r-x+”文件夹权限?- Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29068724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get "drwx---r-x+" folder permission using CHMOD? - Bash script
提问by Wcatter
I am facing a problem when moving some files across my network and seems to be caused by file permissions.
我在通过网络移动某些文件时遇到问题,这似乎是由文件权限引起的。
Currently I have folders with this permissions drwxrwxrwx. I need to run a bash script that change permissions to drwx---r-x+
目前我有具有此权限的文件夹 drwxrwxrwx。我需要运行一个 bash 脚本来更改 drwx---r-x+ 的权限
ACL needs to be there.
ACL 需要在那里。
I don't quite understand how can I achieve the same permissions using CHMOD commands. I have tried so far:
我不太明白如何使用 CHMOD 命令获得相同的权限。到目前为止我已经尝试过:
chmod -R ugo=rx "file"
chmod -R ugo=rx "文件"
But this seems to change to dr-xr-xr-x, which is not enough...
但这似乎变成了dr-xr-xr-x,这还不够……
So the question is, which command should I run to achieve drwx---r-x+ ??
所以问题是,我应该运行哪个命令来实现 drwx---r-x+ ??
Thanks in advance.
提前致谢。
PS. This command must run in MACOSX Maveriks so "setfacl" command will not help.
附注。此命令必须在 MACOSX Maveriks 中运行,因此“setfacl”命令将无济于事。
回答by ghoti
The permissions drwx---r-x+
break down as follows:
权限drwx---r-x+
细分如下:
d
is a directory, of course.rwx
means it's readable, writeable and accessible by the user. These three bits can be represented by the octal number7
.---
means that the three aforementioned bits are NOT set for the group assigned to the directory. No bits are set, so the octal number is0
.r-x
means that users who aren't matched by the first two categories -- that is, everybody else, or "other" -- can read and access content of the directory, but can't write to it. The bits here are in the ones column and the fours column, so the octal number that represents this permission is5
.+
indicates that there is "extended security information" associated with this directory which isn't shown in standardls
"long format". An access control list, for example.
d
当然是目录。rwx
意味着它是可读,可写和可访问由üSER。这三位可以用八进制数表示7
。---
装置,其上述三个位不用于设置克分配给目录roup。没有设置位,所以八进制数是0
。r-x
意味着谁不是由前两类匹配的用户-也就是其他人,或“ Ø疗法” -可以阅读和目录的访问内容,但不能写入。这里的位在一个列和四列中,所以代表这个权限的八进制数是5
。+
表示存在与此目录关联的“扩展安全信息”,该信息未以标准ls
“长格式”显示。例如,访问控制列表。
To set the basic permissions of this directory, you can use either the octal short-hand:
要设置此目录的基本权限,您可以使用八进制简写:
$ chmod 705 directoryname
or you can use the "symbolic" representation:
或者您可以使用“符号”表示:
$ chmod u+rwx,g-rwx,o+rx-w directoryname
Obviously, the shorthand is ... shorter.
显然,简写是……更短。
For the extended security information denoted by the +
, you'd need to find out what is set up in order to replicate it. The ls
command has a -e
option to have it show extended security settings.
对于由 表示的扩展安全信息+
,您需要找出设置了什么才能复制它。该ls
命令有一个-e
选项可以显示扩展的安全设置。
To actually setyour ACLs from the command line, you'd use chmod'a =a
, -a
and +a
options. Documentation about this is available in OSX from man chmod
. From that man page:
要实际设置从命令行将ACL,您会使用chmod'a =a
,-a
和+a
选项。在 OSX 中可以从man chmod
. 从那个手册页:
Examples
# ls -le
-rw-r--r--+ 1 juser wheel 0 Apr 28 14:06 file1
owner: juser
1: admin allow delete
# chmod =a# 1 "admin allow write,chown"
# ls -le
-rw-r--r--+ 1 juser wheel 0 Apr 28 14:06 file1
owner: juser
1: admin allow write,chown