chmod命令介绍
下面介绍如何使用chmod命令来设定和修改文件的权限位。
首先,chmod命令本身的执行也有限制,普通用户只能修改自己的文件的权限位,超级用户可以使用chmod修改任意用户任意文件的权限。使用chmod的方法为chmod [option] mode file. 常用的选项就是-R,用来对整个目录及其子目录中的文件进行模式(权限)修改。mode可以由两种方式指定,一种是由字母表达式表示的相对修改方式,一种是以4位8进制表示的绝对方式。
第一种方式:chmod [ugoa][+-=][rwxst] file. u指代user,g指代group,o指代other,a指代all。+-=分别执行指代增加、减少、设定相应权限(由后面的参数指定)。rwxst分别指代读、写、执行、set-user-id/set-group-id、sticky-bit粘滞位。整体上理解,就是对哪类用户(ugoa,为a时可省略)执行哪些权限(rwxst)的什么修改(+-=)。示例:
1 2 3 4 5 6 7 8 9 10 11 12 | $ chmod u-x a.out $ ll a.out -rw-r-xr-x 1 dutor dutor 7.1K 2010-08-08 13:33 a.out $ chmod +t a.out $ ll a.out -rw-r-xr-t 1 dutor dutor 7.1K 2010-08-08 13:33 a.out $ chmod g=rs a.out $ ll a.out -rw-r-Sr-t 1 dutor dutor 7.1K 2010-08-08 13:33 a.out $ chmod a+x a.out $ ll a.out -rwxr-sr-t 1 dutor dutor 7.1K 2010-08-08 13:33 a.out |