chmod
安装 ACL 工具
更新包列表并安装
acl
包:sudo apt update sudo apt install acl
为现有文件添加执行权限
为目录下的所有现有文件添加执行权限:
sudo find /path/to/directory -type f -exec chmod +x {} \;
为新添加的文件设置默认执行权限
为目录设置默认 ACL:
sudo setfacl -d -m u::rwx /path/to/directory sudo setfacl -d -m g::r-x /path/to/directory sudo setfacl -d -m o::r-x /path/to/directory
验证设置:
getfacl /path/to/directory
示例
假设你要为 /home/user/scripts
目录下的所有文件添加执行权限,并确保新添加的文件也拥有执行权限,以下是具体的命令:
安装
acl
工具:sudo apt update sudo apt install acl
为现有文件添加执行权限:
sudo find /home/user/scripts -type f -exec chmod +x {} \;
为目录及其内容设置执行权限:
sudo find /home/user/scripts -type d -exec chmod 755 {} \; sudo find /home/user/scripts -type f -exec chmod 755 {} \;
为目录设置默认 ACL:
sudo setfacl -d -m u::rwx /home/user/scripts sudo setfacl -d -m g::r-x /home/user/scripts sudo setfacl -d -m o::r-x /home/user/scripts
验证 ACL 设置:
getfacl /home/user/scripts
通过上述步骤,你可以确保目录下的所有现有文件和新添加的文件都具有执行权限。这对于需要自动执行脚本的目录尤其有用。