linux15-chmod修改文件,文件夹权限信息

linux15-chmod


chmod

change mode

修改文件 ,文件夹的权限信息

只有所属用户或root用户可以修改

chmod [-R] 权限 文件或文件夹

选项 -R, 对文件夹内的全部内容应用同样的操作(遍历)

# 将hello.txt的文件权限修改为rwxr-x--x
# u,user; g,group; o,other
chmod u=rwx,g=rx,o=x hello.txt
# test文件夹及内部的所有内容权限修改为rwxr-x--x
chmod -R u=rwx,g=rx,o=x test

# 查看/tmp/test/test.txt文件信息
# 显示其他用户权限为r--,具有读取权限
ll /tmp/test/test.txt
# 切换普通用户test10, 使用cat读取文件,成功读取
su - test10
cat /tmp/test/test.txt

# 切换root用户, 修改文件权限为rwxrwx--x, 此时其他用户不具有读取权限
su - root
chmod u=rwx,g=rwx,o=x /tmp/test/test.txt

# 再次切换普通用户test10, 使用cat读取文件, 读取失败
su - test10
cat /tmp/test/test.txt


数字表示的文件权限

数字权限:

  • r-- :4

  • -w-:2

  • --x:1

  • rw- :6

  • r-x :5

  • -wx :3

  • rwx :7


例如751就代表 u=rwx, g=rx, o=x

可以借助二进制理解


将hello.txt的权限修改为r-x--xr-x

chmod 515 hello.txt

将hello.txt的权限修改为-wx-w-rw-

chmod 326 hello.txt

将hello.txt的权限修改为123

chmod --x-w--wx hello.txt
posted @   HIK4RU44  阅读(69)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示