你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Linux开发
Linux文件权限,chmod
 
Linux文件权限,chmod
 
权限符号意义
符号 代表意义 数字
r
文件:可读
路径:仅能读取路径结构列表
4
w
文件:可写
路径:可新增、删除、移动路径下的文件
2
x
文件:可执行
路径:可进入该路径,访问该路径下的文件
1
s
suid:仅对二进制文件有效,如/usr/bin/passwd
sgid:对文件和路径都有效
使文件有暂时拥有所有者或群组的权限
4
2
 
t sbit:主要对路径有效。只能删除自建的文件,如/tmp/ 1
 
主要语法
chmod [option] mode[,mode]... file...
chmod [option] octal-mode file...
 
mode
改变文件权限可以通过2种模式。符号模式和8进制数字模式。
符号模式 
chmod
u(拥有者)
g(群组)
o(其他)
a(所有)
+(加入)
-(减去)
=(设定)
r(可读)
w(可写)
x(可执行)
s(suid/sgid)
t(sbit)
file
 
8进制数字模式
 
suid/sgid/sbit
拥有者
群组
其他
 
chomod
0-7
0-7
0-7
0-7
file
r=4,w=2,x=1,rwx=7,rw=6,rx=5
suid=4,sgid=2,sbit=1
 
用例
1 用2种模式改变文件权限,将此文件变成可执行文件,并且其他人无法修改
Linux代码  
$ chmod 755 ~/testfile  
$ chmod u=rwx,go=rx ~/testfile  
 
2 使文件对于所有用户,添加可写的权限
Linux代码  
$ chmod a+w ~/testfile  
 
3 用2种模式,给可执行文件加入suid权限
Linux代码  
$ chmod 4755 ~/testfile            //testfile原权限为755  
$ chomd u+s ~/testfile  
 
4用2种模式,给路径加入sgid权限。常用于群组中用户间数据的共享
Linux代码  
$ chomd 2755 ~/testpath/           //testpath原权限为755  
$ chmod g+s ~/testpath/  
 
5 用2种模式,给路径加入sbit权限
Linux代码  
$ chmod 1755 ~/testpath            //tsetpath原权限为755  
$ chmod o+t ~/testpath  
 
  推荐精品文章

·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录
·2023年10月目录
·2023年9月目录 
·2023年8月目录 
·2023年7月目录
·2023年6月目录 
·2023年5月目录
·2023年4月目录 
·2023年3月目录 
·2023年2月目录 
·2023年1月目录 

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089