⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perm.texi

📁 Linux下文件工具。
💻 TEXI
字号:
Each file has a set of @dfn{permissions} that control the kinds ofaccess that users have to that file.  The permissions for a file arealso called its @dfn{access mode}.  They can be represented either insymbolic form or as an octal number.@menu* Mode Structure::              Structure of file permissions.* Symbolic Modes::              Mnemonic permissions representation.* Numeric Modes::               Permissions as octal numbers.@end menu@node Mode Structure@section Structure of File PermissionsThere are three kinds of permissions that a user can have for a file:@enumerate@item@cindex read permissionpermission to read the file.  For directories, this means permission tolist the contents of the directory.@item@cindex write permissionpermission to write to (change) the file.  For directories, this meanspermission to create and remove files in the directory.@item@cindex execute permissionpermission to execute the file (run it as a program).  For directories,this means permission to access files in the directory.@end enumerateThere are three categories of users who may have different permissionsto perform any of the above operations on a file:@enumerate@itemthe file's owner;@itemother users who are in the file's group;@itemeveryone else.@end enumerate@cindex owner, default@cindex group owner, defaultFiles are given an owner and group when they are created.  Usually theowner is the current user and the group is the group of the directorythe file is in, but this varies with the operating system, thefilesystem the file is created on, and the way the file is created.  Youcan change the owner and group of a file by using the @code{chown} and@code{chgrp} commands.In addition to the three sets of three permissions listed above, afile's permissions have three special components, which affect onlyexecutable files (programs) and, on some systems, directories:@enumerate@item@cindex setuidset the process's effective user ID to that of the file upon execution(called the @dfn{setuid bit}).  No effect on directories.@item@cindex setgidset the process's effective group ID to that of the file upon execution(called the @dfn{setgid bit}).  For directories on some systems, putfiles created in the directory into the same group as the directory, nomatter what group the user who creates them is in.@item@cindex sticky@cindex swap space, saving text image in@cindex text image, saving in swap space@cindex restricted deletion flagsave the program's text image on the swap device so it will load morequickly when run (called the @dfn{sticky bit}).  For directories on somesystems, prevent users from removing or renaming a file in a directoryunless they own the file or the directory; this is called the@dfn{restricted deletion flag} for the directory.@end enumerate@node Symbolic Modes@section Symbolic Modes@cindex symbolic modes@dfn{Symbolic modes} represent changes to files' permissions asoperations on single-character symbols.  They allow you to modify eitherall or selected parts of files' permissions, optionally based ontheir previous values, and perhaps on the current @code{umask} as well(@pxref{Umask and Protection}).The format of symbolic modes is:@example@r{[}ugoa@dots{}@r{][[}+-=@r{][}rwxXstugo@dots{}@r{]}@dots{}@r{][},@dots{}@r{]}@end exampleThe following sections describe the operators and other details ofsymbolic modes.@menu* Setting Permissions::          Basic operations on permissions.* Copying Permissions::          Copying existing permissions.* Changing Special Permissions:: Special permissions.* Conditional Executability::    Conditionally affecting executability.* Multiple Changes::             Making multiple changes.* Umask and Protection::              The effect of the umask.@end menu@node Setting Permissions@subsection Setting PermissionsThe basic symbolic operations on a file's permissions are adding,removing, and setting the permission that certain users have to read,write, and execute the file.  These operations have the followingformat:@example@var{users} @var{operation} @var{permissions}@end example@noindentThe spaces between the three parts above are shown for readability only;symbolic modes cannot contain spaces.The @var{users} part tells which users' access to the file is changed.It consists of one or more of the following letters (or it can be empty;@pxref{Umask and Protection}, for a description of what happens then).  Whenmore than one of these letters is given, the order that they are in doesnot matter.@table @code@item u@cindex owner of file, permissions forthe user who owns the file;@item g@cindex group, permissions forother users who are in the file's group;@item o@cindex other permissionsall other users;@item aall users; the same as @samp{ugo}.@end tableThe @var{operation} part tells how to change the affected users' accessto the file, and is one of the following symbols:@table @code@item +@cindex adding permissionsto add the @var{permissions} to whatever permissions the @var{users}already have for the file;@item -@cindex removing permissions@cindex subtracting permissionsto remove the @var{permissions} from whatever permissions the@var{users} already have for the file;@item =@cindex setting permissionsto make the @var{permissions} the only permissions that the @var{users}have for the file.@end tableThe @var{permissions} part tells what kind of access to the file shouldbe changed; it is zero or more of the following letters.  As with the@var{users} part, the order does not matter when more than one letter isgiven.  Omitting the @var{permissions} part is useful only with the@samp{=} operation, where it gives the specified @var{users} no accessat all to the file.@table @code@item r@cindex read permission, symbolicthe permission the @var{users} have to read the file;@item w@cindex write permission, symbolicthe permission the @var{users} have to write to the file;@item x@cindex execute permission, symbolicthe permission the @var{users} have to execute the file.@end tableFor example, to give everyone permission to read and write a file,but not to execute it, use:@examplea=rw@end exampleTo remove write permission for from all users other than the file'sowner, use:@examplego-w@end example@noindentThe above command does not affect the access that the owner ofthe file has to it, nor does it affect whether other users canread or execute the file.To give everyone except a file's owner no permission to do anything withthat file, use the mode below.  Other users could still remove the file,if they have write permission on the directory it is in.@examplego=@end example@noindentAnother way to specify the same thing is:@exampleog-rxw@end example@node Copying Permissions@subsection Copying Existing Permissions@cindex copying existing permissions@cindex permissions, copying existingYou can base a file's permissions on its existing permissions.  To dothis, instead of using @samp{r}, @samp{w}, or @samp{x} after theoperator, you use the letter @samp{u}, @samp{g}, or @samp{o}.  Forexample, the mode@exampleo+g@end example@noindentadds the permissions for users who are in a file's group to thepermissions that other users have for the file.  Thus, if the filestarted out as mode 664 (@samp{rw-rw-r--}), the above mode would changeit to mode 666 (@samp{rw-rw-rw-}).  If the file had started out as mode741 (@samp{rwxr----x}), the above mode would change it to mode 745(@samp{rwxr--r-x}).  The @samp{-} and @samp{=} operations workanalogously.@node Changing Special Permissions@subsection Changing Special Permissions@cindex changing special permissionsIn addition to changing a file's read, write, and execute permissions,you can change its special permissions.  @xref{Mode Structure}, for asummary of these permissions.To change a file's permission to set the user ID on execution, use@samp{u} in the @var{users} part of the symbolic mode and@samp{s} in the @var{permissions} part.To change a file's permission to set the group ID on execution, use@samp{g} in the @var{users} part of the symbolic mode and@samp{s} in the @var{permissions} part.To change a file's permission to stay permanently on the swap device,use @samp{o} in the @var{users} part of the symbolic mode and@samp{t} in the @var{permissions} part.For example, to add set user ID permission to a program,you can use the mode:@exampleu+s@end exampleTo remove both set user ID and set group ID permission fromit, you can use the mode:@exampleug-s@end exampleTo cause a program to be saved on the swap device, you can usethe mode:@exampleo+t@end exampleRemember that the special permissions only affect files that areexecutable, plus, on some systems, directories (on which they havedifferent meanings; @pxref{Mode Structure}).Also, the combinations @samp{u+t}, @samp{g+t}, and @samp{o+s} have no effect.The @samp{=} operator is not very useful with special permissions; forexample, the mode:@exampleo=t@end example@noindentdoes cause the file to be saved on the swap device, but it alsoremoves all read, write, and execute permissions that users not in thefile's group might have had for it.@node Conditional Executability@subsection Conditional Executability@cindex conditional executabilityThere is one more special type of symbolic permission: if you use@samp{X} instead of @samp{x}, execute permission is affected only if thefile already had execute permission or is a directory.  It affectsdirectories' execute permission even if they did not initially have anyexecute permissions set.For example, this mode:@examplea+X@end example@noindentgives all users permission to execute files (or search directories) ifanyone could before.@node Multiple Changes@subsection Making Multiple Changes@cindex multiple changes to permissionsThe format of symbolic modes is actually more complex than describedabove (@pxref{Setting Permissions}).  It provides two ways to makemultiple changes to files' permissions.The first way is to specify multiple @var{operation} and@var{permissions} parts after a @var{users} part in the symbolic mode.For example, the mode:@exampleog+rX-w@end example@noindentgives users other than the owner of the file read permission and, ifit is a directory or if someone already had execute permissionto it, gives them execute permission; and it also denies them writepermission to the file.  It does not affect the permission that theowner of the file has for it.  The above mode is equivalent tothe two modes:@exampleog+rXog-w@end exampleThe second way to make multiple changes is to specify more than onesimple symbolic mode, separated by commas.  For example, the mode:@examplea+r,go-w@end example@noindentgives everyone permission to read the file and removes writepermission on it for all users except its owner.  Another example:@exampleu=rwx,g=rx,o=@end example@noindentsets all of the non-special permissions for the file explicitly.  (Itgives users who are not in the file's group no permission at all forit.)The two methods can be combined.  The mode:@examplea+r,g+x-w@end example@noindentgives all users permission to read the file, and gives users who are inthe file's group permission to execute it, as well, but not permissionto write to it.  The above mode could be written in several differentways; another is:@exampleu+r,g+rx,o+r,g-w@end example@node Umask and Protection@subsection The Umask and Protection@cindex umask and modes@cindex modes and umaskIf the @var{users} part of a symbolic mode is omitted, it defaults to@samp{a} (affect all users), except that any permissions that are@emph{set} in the system variable @code{umask} are @emph{not affected}.The value of @code{umask} can be set using the@code{umask} command.  Its default value varies from system to system.@cindex giving away permissionsOmitting the @var{users} part of a symbolic mode is generally not usefulwith operations other than @samp{+}.  It is useful with @samp{+} becauseit allows you to use @code{umask} as an easily customizable protectionagainst giving away more permission to files than you intended to.As an example, if @code{umask} has the value 2, which removes writepermission for users who are not in the file's group, then the mode:@example+w@end example@noindentadds permission to write to the file to its owner and to other users whoare in the file's group, but @emph{not} to other users.  In contrast,the mode:@examplea+w@end example@noindentignores @code{umask}, and @emph{does} give write permission forthe file to all users.@node Numeric Modes@section Numeric Modes@cindex numeric modes@cindex file permissions, numeric@cindex octal numbers for file modesFile permissions are stored internally as integers.  As analternative to giving a symbolic mode, you can give an octal (base 8)number that corresponds to the internal representation of the new mode.This number is always interpreted in octal; you do not have to add aleading 0, as you do in C.  Mode 0055 is the same as mode 55.A numeric mode is usually shorter than the corresponding symbolicmode, but it is limited in that it cannot take into account a file'sprevious permissions; it can only set them absolutely.On most systems, the permissions granted to the user,to other users in the file's group,and to other users not in the file's group are each stored as threebits, which are represented as one octal digit.  The three specialpermissions are also each stored as one bit, and they are as a grouprepresented as another octal digit.  Here is how the bits are arranged,starting with the lowest valued bit:@exampleValue in  CorrespondingMode      Permission          Other users not in the file's group:   1      Execute   2      Write   4      Read          Other users in the file's group:  10      Execute  20      Write  40      Read          The file's owner: 100      Execute 200      Write 400      Read          Special permissions:1000      Save text image on swap device2000      Set group ID on execution4000      Set user ID on execution@end exampleFor example, numeric mode 4755 corresponds to symbolic mode@samp{u=rwxs,go=rx}, and numeric mode 664 corresponds to symbolic mode@samp{ug=rw,o=r}.  Numeric mode 0 corresponds to symbolic mode@samp{ugo=}.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -