One linux command every day (27): linuxchmod command

Source: Internet
Author: User
Tags touch command
One linux command (27) every day: linuxchmod command link: One linux command every day (1): ls command restart (2): cd command http://www.2cto.com/ OS /201210/163050.html#every day ..
One linux command every day (27): linux chmod command link: One linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; One linux command every day (3): pwd command http://www.2cto.com/os/201210/163462.html ; One linux command every day (4): mkdir command http://www.2cto.com/os/201210/163463.html ; One linux command every day (5): rm command http://www.2cto.com/os/201210/163662.html ; One linux command (6) every day: rmdir command http://www.2cto.com/os/201210/164017.html ; One linux command (7) every day: mv command http://www.2cto.com/os/201210/164247.html ; One linux command every day (8): cp command http://www.2cto.com/os/201210/164254.html ; One linux command every day (9): touch Command http://www.2cto.com/os/201211/165699.html ; One linux command every day (10): cat command http://www.2cto.com/os/201211/165989.html ; One linux command every day (11): nl command http://www.2cto.com/os/201211/165990.html One linux command every day (12): more command http://www.2cto.com/os/201211/165994.html One linux command every day (13): less command http://www.2cto.com/os/201211/165998.html One linux command every day (14): head Command http://www.2cto.com/os/201211/166191.html One linux command every day (15): tail command http://www.2cto.com/os/201211/168702.html One linux command every day (16): which command http://www.2cto.com/os/201211/168890.html A linux command (17) every day: whereis command http://www.2cto.com/os/201211/168893.html One linux command (18) every day: locate command http://www.2cto.com/os/201211/168895.html One linux command every day (19): find command overview http://www.2cto.com/os/201211/168897.html One linux command every day (20): find command exec http://www.2cto.com/os/201211/168901.html One linux command (21) every day: find command xargs http://www.2cto.com/os/201211/168903.html A linux command (22) every day: detailed description of the parameters of the find Command http://www.2cto.com/os/201211/168912.html A linux command (23) every day: Linux directory structure http://www.2cto.com/os/201211/170430.html One linux command every day (24): Linux file type and extension http://www.2cto.com/os/201211/170431.html One linux command every day (25): Explanation of linux file attributes http://www.2cto.com/os/201211/170434.html One linux command every day (26): use SecureCRT to upload and download files http://www.2cto.com/os/201211/172022.html The chmod command is used to change the access permissions of linux system files or directories. Use it to control access to files or directories. This command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers. In www.2cto.com Linux, each file and directory has access permission to determine who can access and operate files and directories. File or directory access permissions are divided into read-only, write-only and executable. Taking a file as an example, the read-only permission indicates that only the content of the file can be read, and any changes to the file are prohibited. The executable permission indicates that the file can be executed as a program. When a file is created, the file owner automatically has the read, write, and executable permissions for the file to facilitate reading and modifying the file. You can also set the access permission to any combination as needed. There are three different types of users who can access files or directories: File owners, users in the same group and other users. The owner is generally the creator of the file. The owner can allow users in the same group to access files and grant the file access permission to other users in the system. In this case, every user in the system can access the files or directories owned by this user.
Each file or directory has three groups of access permissions. each group is represented by three digits, which are the read, write, and execution permissions of the file owner; the read, write, and execution permissions of users in the same group as the owner; the read, write, and execution permissions of other users in the system. When you use the ls-l command to display detailed information about a file or directory, the leftmost column lists the file access permissions. Example: Command: ls-al output: [root @ localhost test] # ll-al total 316 lrwxrwxrwx 1 root 11 11-22 linklog. log-> log2012.log-rw-r -- 1 root 302108 11-13 06:03 log2012.log-rw-r -- 1 root 61 11-13 06:03 log2013.log-rw-r -- r -- 1 root 0 11-13 06:03 log2014.log-rw-r -- 1 root 0 11-13 06:06 log2015.log-rw-r -- 1 root 0 11 -16 log2016.log-rw-r -- 1 root 0 11-16 log2017.log
Take log2012.log as an example:-rw-r -- 1 root 296 K 11-13 log2012.log has 10 locations in the first column, and the first character specifies the file type. In general, a directory is also a file. If the first character is a horizontal line, it indicates a non-directory file. If it is d, it indicates a directory. From the second character to the tenth character, there are 9 characters in total, and a group of 3 characters represents the permissions of the three groups of users on files or directories. The permission character uses a horizontal line to indicate an empty permit. r indicates read-only, w indicates write, and x indicates executable. For example,-rw-r -- indicates that log2012.log is a common file. The owner of log2012.log has the read and write permissions. users in the same group as log2012.log have only the read permission; other users only have read permission. After determining the access permission for a file, you can use the chmod command provided by Linux to reset different access permissions. You can also use the chown command to change the owner of a file or directory. Use the chgrp command to change the user group of a file or directory. The chmod command is very important for changing the access permissions of files or directories. You can use it to control access to files or directories. The details of the chmod command are as follows. 1. command format: chmod [-cfvR] [-- help] [-- version] mode file 2. command: used to change the access permission of a file or directory, and use it to control the access permission of a file or directory. 3. command parameter: Required parameter:-c when a change occurs, report processing information-f error information is not output-R is used to process the specified directory and all files in its subdirectories-detailed processing information displayed when running-select the parameter: -- reference = <目录或者文件> Set to have the same permissions for the specified directory or file -- version displays version information <权限范围> + <权限设置> Grant specified permissions to directories or files within the permission range <权限范围> - <权限设置> Delete the specified permission of a directory or file within the permission range <权限范围> = <权限设置> Set the directory or file permission within the permission range to the specified value permission range: u: directory or file's current user g: directory or file's current group o: except for the current user or group of directories or files, user or group a: all users and Group permission code: r: read permission. the number 4 indicates w: write permission, use number 2 to indicate x: execution permission. use number 1 to indicate-: delete permission. use number 0 to indicate s: special permission. this command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers. 1 ). text setting method: chmod [who] [+ |-| =] [mode] file name 2 ). to set the number, we must first understand the meaning of the attributes represented by numbers: 0 indicates no permission, 1 indicates executable permission, 2 indicates writable permission, and 4 indicates readable permission, and then add them. Therefore, the format of the numeric attribute should be three octal numbers from 0 to 7. The order is (u) (g) (o ). For example, if you want the owner of a file to have the "read/write" permission, you need to set 4 (readable) + 2 (writable) to 6 (read/write ). The general format of the number setting method is: chmod [mode]. the correspondence between the number of file names and characters is as follows: r = 4, w = 2, x = 1 if the rwx attribute is required, 4 + 2 + 1 = 7 if the rw-attribute is required, 4 + 2 = 6; if the r-x attribute is required, 4 + 1 = 7.
4. run the command chmod a + x log2012.log to add all file user groups and run the following command: [root @ localhost test] # ls-al log2012.log-rw-r -- 1 root 302108 11-13 03 log2012.log [root @ localhost test] # chmod a + x log2012.log [root @ localhost test] # ls-al log2012.log-rwxr-xr-x 1 root 302108 11-13 03 log2012.log [root @ localhost test] # note: that is, set the log2.2.log attribute of the file to: add execution permissions to the file owner (u); add execution permissions to users in the same group as the file owner (g); other users (o) add execution permission. Example 2: run the command chmod ug + w, o-x log2012.log to modify different user permissions at the same time. the output is as follows: [root @ localhost test] # ls-al log2012.log-rwxr-xr-x 1 root 302108 11-13 06:03 log2012.log [root @ localhost test] # chmod ug + w, o-x log2012.log [root @ localhost test] # ls-al log2012.log-rwxrwxr -- 1 root 302108 11-13 06:03 log2012.log description: Set the attribute of the file text: the write permission is added to the file owner (u), and the write permission is added to the users (g) in the same group as the file owner. other users (o) delete execution permission instances. 3: delete file permission command: chmod a-x log2012.log output: [root @ localhost test] # ls-al log2012.log-rwxrwxr -- 1 root 302108 11-13 03 log2012.log [root @ localhost test] # chmod a-x log2012.log [root @ localhost test] # ls-al log2012.log-rw-r -- 1 root 302108 11-13 log2012.log description: delete the executable permission instance of all users 4: Use the "=" permission setting command: chmod u = x log2012.log output: [root @ localhost test] # ls-al log2012.log-rw-r -- 1 root 302108 11-13 03 log2012.log [root @ localhost test] # chmod u = x log2012.log [root @ localhost test] # ls-al log2012.log --- xrw-r -- 1 root 302108 11-13 log2012.log description: revoke all the original permissions and grant the owner the read permission to instance 5: Add the permission command to all files in a directory and its subdirectories: chmod-R u + x test4 output: [root @ localhost test] # cd test4 [root @ localhost test4] # ls-al total 312drwxrwxr-x 2 root 4096 11-13. drwxr-xr-x 5 root 4096 11-22 .. -rw-r -- 1 root 302108 11-12 log2012.log-rw-r -- 1 root 61 11-12 log2013.log-rw-r -- 1 root 0 11-12 log2014.log [root @ localhost test4] # cd .. [root @ localhost test] # chmod-R u + x test4 [root @ localhost test] # cd test4 [root @ localhost test4] # total ls-al 312drwxrwxr-x 2 root 4096 11 -13. drwxr-xr-x 5 root 4096 11-22 .. -rwxr -- r -- 1 root 302108 11-12 log2012.log-rwxr -- r -- 1 root 61 11-12 log2013.log-rwxr -- r -- 1 root 0 11-12 log2014.log description: recursively assign permissions to the owner of all files and subdirectories in the test4 Directory. Other instances: 1 ). command: chmod 751 file description: read, write, and execute (7) permissions are assigned to the file owner, and read and execute (5) permissions are assigned to the group where the file is located, assign permissions for execution (1) to other users (2 ). command: chmod u = rwx, g = rx, o = x file description: another form of the above example 3 ). command chmod = r file description: assign read permissions to all users 3 ). command: chmod 444 file description: same as example 4 ). command: chmod a-wx, a + r file description: Same as above
Related Article

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.