Aur*_*ron 5 bash recursion file-permissions
我需要一个Bash脚本来更改目录和所有子目录中所有文件的文件权限。它的行为应如下所示:
for each file in directory (and subdirectories)
if i am the owner of the file
if it is a directory
chmod 770 file
else
chmod 660 file
Run Code Online (Sandbox Code Playgroud)
我想这不是一个艰巨的任务,但是我对Bash脚本没有很丰富的经验。感谢您的帮助!:D
您可以通过两次调用该find命令来完成此操作,并可-user选择按用户过滤和-type按文件类型过滤:
find . -user "$USER" -type d -exec echo chmod 770 {} +
find . -user "$USER" -not -type d -exec echo chmod 660 {} +
Run Code Online (Sandbox Code Playgroud)
测试后删除echo,才能真正改变权限。