linux 文件权限

来源:互联网 发布:麻将机器人ai算法思路 编辑:程序博客网 时间:2024/05/06 15:46

指令名称 : chmod 
使用权限 : 所有使用者 
使用方式 : chmod [-cfvR] [--help] [--version] mode file... 
说明 : Linux/Unix 的档案调用权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所调用。 
参数
mode :
权限设定字串,格式如下 : [ugoa...][[+-=][rwxX]...][,...],其中 
u
表示该档案的拥有者,

g 表示与该档案的拥有者属于同一个群体(group)者,

o 表示其他以外的人,

a 表示这三者皆是。 
+
表示增加权限、- 表示取消权限、= 表示唯一设定权限。 
r
表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。 
-c :
若该档案权限确实已经更改,才显示其更改动作 
-f :
若该档案权限无法被更改也不要显示错误讯息 
-v :
显示权限变更的详细资料 
-R :
对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更) 

范例 :将档案 file1.txt 设为所有人皆可读取
chmod ugo+r file1.txt 
将档案 file1.txt 设为所有人皆可读取
chmod a+r file1.txt 
将档案 file1.txt file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入
chmod ug+w,o-w file1.txt file2.txt 
ex1.py 设定为只有该档案拥有者可以执行
chmod u+x ex1.py 
将目前目录下的所有档案与子目录皆设为任何人可读取
chmod -R a+r * 
此外chmod也可以用数字来表示权限如 chmod 777 file 
语法为:chmod abc file 
其中a,b,c各为一个数字,分别表示UserGroup、及Other的权限。 
r=4
w=2x=1 
若要rwx属性则4+2+1=7 
若要rw-属性则4+2=6 
若要r-x属性则4+1=5 
范例: 
chmod a=rwx file 
 
chmod 777 file 
效果相同 
chmod ug=rwx,o=x file 
 
chmod 771 file 
效果相同 
若用chmod 4755 filename可使此程序具有root的权限

 

 

 

 

首先我们root登录系统后输入ls –al 会有如下所示: 
[root@tsai root]# ls -al
total 64
drwxr-x--- 4 root root 4096 Feb 14 22:02 .
drwxr-xr-x 23 root root 4096 Feb 16 13:35 ..
-rw-r--r-- 1 root root 1210 Feb 10 06:03 anaconda-ks.cfg
-rw------- 1 root root 12447 Feb 14 23:22 .bash_history
-rw-r--r-- 1 root root 24 Jun 11 2000 .bash_logout
-rw-r--r-- 1 root root 234 Jul 6 2001 .bash_profile
-rw-r--r-- 1 root root 217 Feb 9 22:06 .bashrc
-rw-r--r-- 1 root root 210 Jun 11 2000 .cshrc
drwx------ 2 root root 4096 Feb 14 21:54 .gnupg
-rw------- 1 root root 8 Feb 14 22:05 .mysql_history
drwx------ 2 root root 4096 Feb 10 00:44 .ssh
-rw-r--r-- 1 root root 196 Jul 11 2000 .tcshrc
-rw-r--r-- 1 root root 1126 Aug 24 1995 .Xresources


整体上属性分七栏
第一栏  [文件属性]
第二栏  [文件数]
第三栏  [拥有者]
第四栏  [所有者群组]
第五栏  [大小]
第六栏  [建档日期]
第七栏  [档名]

原创粉丝点击