

























2026-04-21 11:02 xiashengwang 阅读(5) 评论() 收藏 举报
chmod 和 chown 修改权限和所有者ls -l file
# 输出:-rw-r--r-- 1 user group 1234 Apr 17 10:00 file
chmod# 符号模式
chmod u+x file # 给所有者加执行权限
chmod g-w file # 删除组的写权限
chmod o=r file # 设置其他人的权限为只读
# 数字模式
chmod 755 file # rwxr-xr-x
chmod 600 file # rw-------
chownchown learner:learners file # 修改所有者和组
chown :learners file # 只改组
echo '#!/bin/bash' > hello.sh
echo 'echo "Hello Linux"' >> hello.sh
chmod +x hello.sh
./hello.sh
mkdir secret
echo "top secret" > secret/data.txt
chmod 700 secret # 只有所有者能进入
su - learner # 切换到普通用户
cd /home/yourname/secret # 会失败(Permission denied)
# 切回 root
chown learner:learner hello.sh
ls -l hello.sh
./script.sh 没有权限:先用 chmod +xchown 需要 root 权限,普通用户只能修改自己文件的组(且必须是组成员)此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。