Linux Learning Notes (4) Rights Management commands for Linux common commands

Source: Internet
Author: User
Tags create directory

(1) chmod

The chmod command is used to change file or directory permissions , and the English original is the permissions mode of a file, where the path is/bin/chmod, and its syntax format is:

chmod [{ugoa}{+-=}{rwx}] [file or directory] or chmod [mode=421] [file or directory]

Where a means that all the permissions for U, G, and O are modified. If you add the-r option, the recursive modify permission is indicated . the number representation of the permission is: R corresponds to the 4,w corresponding to the 2,x corresponds to 1, therefore, the rwxrw-r-corresponding to the digital permission is 764. Note: only root and owner can change the permissions of the file or directory !

In the/tmp directory, create a test.txt file and modify its permissions to owner (u) to remove write permissions, user groups (g) and others (O) with Write permissions, and all three have execute permissions.

Use the number command to change the owner's permissions to readable writable, and to change the permissions of the user group and others to read-only.

Create directory A under the/tmp directory, create directory b under Directory A, and then use the-r option to recursively modify permissions for A and B.

Summary of file directory permissions:

Representative character

Permissions

The meaning of the file

The meaning of the directory

R

Read permissions

To view the contents of a file

Can list content in a directory (such as LS)

W

Write permissions

Can modify the contents of the file

You can create and delete files in the directory (such as TOUCH,RM)

X

Execute permissions

Executable file

access to catalogs (e.g. CD)

Note: Deleting a file is a prerequisite for the user to have write access to the directory in which the file resides, rather than having write access to the file!!!

(2) Chown

The chown command is used to change the owner of a file or directory , and the English original is the ownership, where the path is/bin/chown, with the syntax format:chown [user] [file or directory], Note Only administrators can change which user the file belongs to .

Create a user ws to log in to the user and create a file Test.txt in the/tmp directory.

It then modifies the file's owning user as root.

(3) Chgrp

The chgrp command is used to change the owning group of a file or directory , and the English original is ownership, where the path is/BIN/CHGRP and the syntax format is:chgrp [user Group] [file or directory]

Also under root user to change the owning group of Test.txt to root.

(4) Umask

The umask command is used to display and set default permissions for the file , and the user file-creation Mask,umask command belongs to the Shell's built-in command in the syntax format:umask [-S], where-s option indicates that the new file default permission is displayed in rwx form .

the direct Input umask command is the permission mask, where the first "0" represents a special permission, the following "022" corresponding to the owner, the group, other people's rights, the mask corresponding to the true permissions: 777-022=755.

Create a new directory test in/TMP, and view its permissions as the default permissions that correspond to the defaults.

[[email protected] ~]# umask-su=rwx,g=rx,o=rx[[email protected] ~]# mkdir/tmp/test[[email protected] ~]# ls-ld/tmp/tes Tdrwxr-xr-x. 2 root root 4096 January   8 00:32/tmp/test[[email protected] ~]#

when creating a new file, the default is no execute permission for security purposes . For example, create a new Test1.txt file under the TMP directory with the following default permissions:

[Email protected] ~]# touch/tmp/test1.txt[[email protected] ~]# ls-l/tmp/test1.txt-rw-r--r--. 1 root root 0 January   8 00:34/tmp/test1.txt[[email protected] ~]#

If the default permission is rwxr-xr--, the corresponding mask is calculated first: 777-754=023, and then the umask can be modified . The corresponding command is as follows:

[Email protected] ~]# umask 023[[email protected] ~]# mkdir/tmp/test2[[email protected] ~]# LS-LD/TMP/TEST2DRWXR-XR--. 2 root root 4096 January   

Linux Learning Notes (4) Rights Management commands for Linux common commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.