17 chmod
是否有一个 unix 命令可以为目录树递归地逐个文件地为该组提供与用户当前拥有的权限相同的权限?即如果文件是用户可写的,它应该成为组可写的,否则它不应该是组可写的,依此类推。
Joe*_*ams 29
感谢 jamessan 向我们展示 g=u。在我的系统上,这似乎有效:
chmod -R g=u dir
Run Code Online (Sandbox Code Playgroud)
我想不出用现有命令来做到这一点的简单方法。也许这样的脚本会有所帮助:
#!/bin/bash
DIR="$1"
find "$DIR" -ls | while read a b perm c d e f g h i file; do
uperm=${perm:1:3}
uperm=$(echo "$uperm" | tr -d '-')
chmod g=$uperm "$file"
done
Run Code Online (Sandbox Code Playgroud)
另外,请记住,用户的某些权限可能不适用于组,反之亦然。