在Linux系统中,文件权限和属性中的 o 和 a 通常与 chmod 命令相关,用于指定权限修改的对象范围。以下是详细解释:
o(Others)bash
chmod o+r file.txt # 允许其他用户读取文件
chmod o-w file.txt # 禁止其他用户写入文件
chmod o+x script.sh # 允许其他用户执行脚本a(All)bash
chmod a+rw file.txt # 所有用户可读/写
chmod a-x script.sh # 所有用户不可执行chmod +x),默认使用 a。| 符号 | 目标用户 | 示例命令 | 效果 |
|---|---|---|---|
u |
所有者(User) | chmod u+x script.sh |
仅所有者可执行 |
g |
所属组(Group) | chmod g-w file.txt |
禁止组内成员写入 |
o |
其他用户(Others) | chmod o+r file.txt |
允许其他用户读取 |
a |
所有用户(All) | chmod a=rw file.txt |
所有用户仅可读/写(重置权限) |
数字权限模式:
如果用数字表示权限(如 755),则无需单独指定 o 或 a,数字已隐含权限分配(如 7=u+rwx, 5=g+rx, 5=o+rx)。
特殊权限:
o 通常与 t(粘滞位,Sticky Bit)结合使用,例如:
chmod o+t /tmp # 设置/tmp目录的粘滞位,防止用户删除他人文件
o:针对其他用户(非所有者、非所属组)。a:针对所有用户(等价于 u+g+o)。通过合理使用这些符号,可以精确控制文件权限,保障系统安全和协作需求。