我需要更改目录中文件的权限,例如:
但是在一个命令中。
我很确定我必须使用
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
关于bash - 在linux中检查文件权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58423265/