📄 chmod.1
字号:
.\" SCCSID: @(#)chmod.1 8.1 9/11/90.TH chmod 1.SH Namechmod \- change file mode.SH Syntax.B chmod[.B \-fR] .I mode file....SH Description.NX R "chmod command".NX A "chmod command" "install command".NX R "mode" "changing"Permissions on files are set according to .I modeand.I fileparameters..PPFor.IR file ,you can specify either a full or partial path. You can specifymultiple files, separated by spaces..PPFor.IR mode ,you specify one of two variants: absolute mode or symbolic mode..SS Absolute ModeFor.I modein absolute form, you specify an octal number constructed from the sumof one or more of the following values:.RS.TP 104000set user ID on execution (applies to executable files only).br.ns.TP 102000set group ID on execution (applies to executable files only).br.ns.TP 101000set sticky bit (see.MS chmod 2for more information).br.ns.TP 100400read by owner.br.ns.TP 100200write by owner.br.ns.TP 100100execute, or search if .I file is a directory, by owner.br.ns.TP 100040read by group.br.ns.TP 100020write by group.br.ns.TP 100010execute, or search if .I file is a directory, by group.br.ns.TP 100004read by others.br.ns.TP 100002write by others.br.ns.TP 100001 execute, or search if.I fileis a directory, by others.RE.PPFor example, the absolute mode value that provides read, write, and execute permission to owner, read and execute permission to group, andread and execute permission to others is 755 (400+200+100+40+10+4+1).The absolute mode value that provides read, write, and executepermission to owner and no permission to group or others is 700(400+200+100)..SS Symbolic ModeTo specify.I modein symbolic form, use the following format:.IP.RI [ who ].I op permission.RI [ "op permission" "] ...".NTSpaces are included in the preceding format so that you can read thearguments; however, as will be shown in examples that follow, you donot enter spaces between mode arguments..NE.PPSpecify.I whousing the letters.B u(for owner),.B g(for group) and.B o(for others) either alone or in combination. You can also specify theletter.B a(for all), which is is equivalent to the letter combination.B ugo.If you omit the.I whoparameter,.B ais assumed. For more information, see .MS umask 2 ..PPFor the.I opparameter, specify the plus sign.RB ( + )to add .I permissionto the file's mode, the minus sign.RB ( \- )to remove.I permissionfrom the file's mode, or the equal sign.RB ( = )to assign.I permissionabsolutely (denying or revoking any permission not explicitly specifiedfollowing the equal sign). The first command in the following exampleprovides group with execute permission for .PN fileain addition to any other permissions group currently has for.PN filea .The second command limits the permission that group has for.PN filebto execute alone:.EXchmod g+x fileachmod g=x fileb.EE.PPFor the.I permissionparameter, specify any combination of the letters.B r(read),.B w(write),.B x(execute),.B s(set owner or group id), and.B t(save text \- sticky). Alternatively, you can specify the letter.BR u ,.BR g ,or.B oto set.I permissionfor the.I whoparameter to be the same as the permission currently granted to theuser category indicated by the letter. In the following example, thegroup.RB ( g )is given the same permissions on .PN fileaas currently granted to owner.RB ( u ):.EXchmod g=u filea.EE.PPYou can revoke all permissions by specifying the.I whoargument followed by.BR = ,and omitting the.I permissionargument. For example, the following command removes all permissionsfrom others for .PN fileb:.EXchmod o= fileb.EE.PPWhen specifying more than one symbolic mode for.IR file ,separate the modes with commas. The mode changes are applied in thesequence specified. In the following example, write permission isadded to the permissions already granted to the owner of .PN fileaand group is then granted the same permissions on .PN fileaas granted the owner:.EXchmod u+w,g=u filea.EE.SH Options.IP \-f 5Inhibits display of errors that are returned if.PN chmodfails to change the mode on a file..IP \-RCauses .PN chmod to recursively descend any directories subordinate to.I fileand to set the specified mode for each file encountered. However,when symbolic links are encountered, .PN chmoddoes not change the mode of the link file and does not traversethe path associated with the link. Note that the .PN \-R option is useful only when.I fileidentifies a directory that is not empty..SH Restrictions.NX R "chmod command" "restricted"The .I permissionletter.B sis used only with .I who letter.B uor.B g..PPOnly the owner of a file or someone logged on as superuser may changethe mode of that file..SH ExamplesUsing absolute mode, provide read, write, and search permission tothe owner, and read and search permission to others for a directorynamed .PN public:.EXchmod 755 ~harris/public.EE.NX R(e) "chmod command".PPUsing absolute mode, set the UID for .PN progrmb execution to be the UID ofof the file owner rather than the UID of the userrunning the program as follows:.EXchmod 4000 progrmb.EE.PPUsing symbolic mode, perform the same operation as described for the preceding example:.EXchmod u=s progrmb.EE.PPUsing symbolic mode, deny write permission to others for the file.PN ourspec:.EXchmod o\-w ourspec.EE.PPUsing symbolic mode, give execute permission on file .PN myprogto all user categories:.EXchmod +x myprog.EE.PPUsing symbolic mode, give write permission to all group members,deny write permission to others, and give search permission to owneron .PN docdir:.EXchmod g+w,o\-r,u+x docdir.EE.PPUsing symbolic mode, give read and execute permissions to others for a directory named .PN programs ,and then recursively descend the paths subordinate to .PN programs, adding the same permissions for others on all files and directoriesincluded in the subordinate paths:.EXchmod \-R o+rx programs.EE.NTIn the preceding example, if .PN programswere the name of a file rather than a directory, .PN chmodwould change the mode only of the .PN programs file..NE.SH See Alsols(1), chmod(2), stat(2), umask(2), chown(8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -