Chmod Command【转】
Source:http://www.thegeekstuff.com/2010/06/chmod-command-examples
Following are the symbolic representation of three different roles:
u is for user, g is for group, and o is for others.
Following are the symbolic representation of three different permissions:
r is for read permission, w is for write permission, x is for execute permission.
Following are few examples on how to use the symbolic representation on chmod.
Add single permission to a file/directory
Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:
$ chmod u+x filename
Add multiple permission to a file/directory
Use comma to separate the multiple permission sets as shown below.
$ chmod u+r,g+x filename
Remove permission from a file/directory
Following example removes read and write permission for the user.
$ chmod u-rx filename
Change permission for all roles on a file/directory
Following example assigns execute privilege to user, group and others (basically anybody can execute this file).
$ chmod a+x filename
Make permission for a file same as another file (using reference)
If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2’s permission will be set exactly same as file1’s permission.
$ chmod --reference=file1 file2
Apply the permission to all the files under a directory recursively
Use option -R to change the permission recursively as shown below.
$ chmod -R 755 directory-name/
( 命令格式:chmod abc file
其中a,b,c各为一个八进制数字,分别表示User、Group、及Other的权限。
4 (100) 表示可读。
2 (010) 表示可写。
1 (001) 表示可执行。
若要rwx属性则4+2+1=7;
若要rw-属性则4+2=6;
若要r-x属性则4+1=5。
例如:# chmod a+rx filename
让所有用户可以读和执行文件filename。
# chmod go-rx filename
取消同组和其他用户的读和执行文件filename的权限。
# chmod 741 filename
让本人可读写执行、同组用户可读、其他用户可执行文件filename。
# chmod -R 755 /home/oracle
递归更改目录权限,本人可读写执行、同组用户可读可执行、其他用户可读可执行)
Change execute permission only on the directories (files are not affected)
On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).
$ chmod u+X *
Note: If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user
浙公网安备 33010602011771号