Permissions common commands of Linux management commands

chmod command

chmod command to change file or directory permissions. In the UNIX system family, the file or directory permissions are controlled to read, write, execute permissions to distinguish three general, and another three kinds of special privileges available for use. Privileged user can use the chmod command to change file and directory, set the way the use of text or numeric code can be. Permissions symbolic link can not be changed, if a user connects to modify permissions on the sign, its role will change in the original file to be linked.

Purview notation as follows:

u User, that is, the owner of the file or directory;
g Group, namely belongs to a group of files or directories;
o Other, in addition to the file or directory owner, or their group, others belong to this range;
a All, that is, all users, comprising the owner, group, and other user belongs;
r read permission, the digital code is "4";
w write access, the digital code is "2";
x execute permissions or switch, the digital code is "1";
- not having any permission, digital code-named "0";
s special function: permission to change the file or directory.

grammar

chmod (option) (parameters)

Options

-c or --changes: effects similar to "-v" parameter, but only the return part of the change; 
-f or --quiet or --silent: no error messages; 
-R & lt or --recursive: recursive processing, the instruction all files and subdirectories under the directory processed together; 
-v or --verbose: display instruction execution; 
--reference = <reference file or directory>: the specified file or directory belongs to group all set to reference and or belongs to the same group directory; 
<purview> + <permissions>: open purview of this option is the file or directory permissions; 
<jurisdiction> - <permissions>: Close purview of the file or directory options permissions; 
<purview> = <permissions>: this option specifies the competence of the authority file or directory is provided;

parameter

Permissions mode: permissions mode specified file;
file: To change the file permissions.

Expand knowledge and examples

Linux users are divided into: owner, group (Group), other (other), Linux system, the case of default, the system account and the general status of all users, as well as information about root, are recorded in the file. Each person's password is recorded in the case file. In addition, all records in the group name inside!/etc/passwd/etc/shadow/etc/group

Analysis chart user rights linux file

Analysis chart user rights linux file

Example: rwx rw- r--

read the attribute value r = @. 4 =
W = write attribute value @ 2 =
X = // execute attribute value = 1

chmod u + x, g + w f01 // provided they can execute permissions for the file can be written members F01 
the chmod = rwx U, G = RW, O = R & lt F01 
the chmod 764 F01 
the chmod of A + X // F01 file f01 is u, g, o are set the executable

chown command

chown command to change the owner and group of a file or directory belongs, this command can authorize a user so that the user becomes the owner of the specified file or set of files that change belongs. The user may be the user or the user D, the user group may be a group name or group ID . The file name can make a list of files separated by spaces in file names can include wildcards.

Only super-user file owners and is available for use this command.

grammar

chown (option) (parameters)

Options

-c or --changes: similar effect "-v" argument, but some only return change; 
-f or --quite or --silent: no error messages; 
-h or --no-dereference: only the symbol attached file modification, without changing any other relevant documents; 
-R & lt or --recursive: recursive processing, all files and subdirectories under the specified directory processed together; 
-v or --version: display instruction execution; 
--dereference: effects and "-h" the same parameters; 
- help : online help; 
--reference = <reference file or directory>: owner belongs to a group specified file or directory, and all references to a set or owner of the directory and belongs to the same group; 
--version: show the version information.

parameter

User: Group: Specify the owner and the working group belongs. When omission ": Groups", changing only the file owner;
File: Specifies the owner to change the list of files and working groups. Support multiple files and targets, support shell wildcards.

Examples

The catalog /usr/mengof all its file below subdirectories into the main liu:

chown -R liu /usr/meng

chgrp command

chgrp command to change the user group file or directory belongs. This command is used to change the file belongs to the user group. Among them, the group name can be a user group of the above mentioned id , it can also be a group name of the user group. File names can be separated by a space to change the list of files that belong to the group, is a collection of files can also be described by a wildcard. If the user is not a super user of the main document or file (root), the group of the file can not be changed.

In the UNIX system family, the control file or directory permissions to the owner and their group to manage. You can use the chgrp command to change file and directory belongs to the group, set the mode using the group name or group ID can be.

grammar

chgrp (option) (parameters)

Options

-c or --changes: similar effect "-v" argument, but some only return change; 
-f or --quiet or --silent: no error messages; 
-h or --no-dereference: only the symbol attached file modification, rather than any other of the relevant documents; 
-R & lt or --recursive: recursive processing, all files and subdirectories under the directory together with the processing instructions; 
-v or --verbose: display instruction execution; 
--reference = <reference file or directory>: the specified file or directory belongs to group all set to their group, and the same reference files or directories;

parameter

  • Group: Specifies the name of the new job;
  • File: Specifies to change the list of files belongs. Use spaces to separate between multiple files or directories.

Examples

The /usr/menguser group of all files and subdirectories under the changed mengxin

chgrp -R mengxin / usr / meng

umask command

umask command to set file permissions to limit new mask. When a new file is created, its initial determined by the file permissions to create a mask. Each time a user registration into the system, umask commands are executed, and automatically sets the mask mode to limit the new file permissions. Users can perform again umask command to change the default value, the new authority will overwrite the old.

grammar

umask (option) (parameters)

Options

-p: output permission mask can be directly executed as instructions; 
-S: symbolically output permission mask.

parameter

Permission mask: assign permissions mask.

Examples

What permissions using the umask command can specify the default permissions will be removed in the new file. For example, you can use the following command to create a mask, so that the write permissions to groups of users, and other users to read, write, and execute permissions are canceled:

umask u=, g=w, o=rwx

After executing this command for the new file created under the permissions of a file without making any changes to the Lord, and the user does not have write permission to the group, all privileges other users have been canceled.

It should be noted: operator "=" umask command and the chmod action in the opposite order. In the chmod command, use it to set permissions assigned, while the remaining rights will be deleted; but in the umask command, it will delete the specified permission rights on the basis of the original.

Create an executable can not directly use the umask command file, the user can subsequently use the chmod command so that it has execute permissions. Suppose execution of the command umask u=, g=w, o=rwx, while the command line, deleting the file do not have permission primary set of users, but the default file permissions or 640 (i.e. rw-r -----), instead of 750 (rwxr-x- -). However, if you create a directory created by the compiler or an executable file that will not so limited. In this case, the execution will be set file permissions.

You can also use octal values ​​to set the mode. Since the rights specified in the umask is deleted from the file, so if the original initialization file permissions are 777, then execute the command umask 022 later, the file permissions will change to 755: If the original initialization file permission is 666, then the file permissions will change to 644.

You can use the following command to check the default permissions for newly created files:

umask -s

-S option displays the current mask represented in characters. If you enter umask command directly, without any parameters, it will display the current octal mask. The system default mask is 0022.

Guess you like

Origin www.cnblogs.com/wuwuyong/p/11817070.html