我需要更改目录中文件的权限,例如:
但是在一个命令中。
我很确定我必须使用chmod
进行更改。我最大的问题实际上是如何知道该组是否具有权限?之后,在单个命令中使用此信息
您可以尝试以下方法:
#!/bin/bash
[ "$(stat -c "%a" "$1" | cut -b 2)" -eq 0 ] && chmod o-rwx "$1"
说明:
stat -c "%a" "$1" # get file permission as octal number
cut -b 2 # extract second number (-> group)
-eq 0 # test if group permissin is 0
&& # then...
chmod o-rwx "$1" # remove other permissions