One linux Command every day (27): linux chmod command link: One linux Command every day (1): ls command http://www.bkjia.com/ OS /210210/163049.html#linuxlinuxcommand every day (2): cd command serial (3 ): pwd command Export (4): mkdir command http://www.bkjia.com/ OS /201210/1620.3.html#a linuxcommand every day (5): rm command Export (6): rmdir command http://www.bkjia.com/ OS /201210 /164017.html; one linux Command every day (7): mv command http://www.bkjia.com/ OS /201210/161097.html?linuxcommand every day (8): cp command serial (9): touch command serial (10): cat command serial (11 ): nl command http://www.bkjia.com/ OS /201211/165990.htmla linuxcommand every day (12): more command http://www.bkjia.com/ OS /201211/165994.htmla linu every day X command (13): less command running (14): head command running (15): tail command http://www.bkjia.com/ OS /201211/168702.htmla linuxcommand every day (16): which command running (17): whereis command running (18): locate command http://www.bkjia.com/ OS /201211/168895.htmla linuxcommand every day (19): fi Nd command overview examples (20): find command exechttp: // www.bkjia.com/ OS /201211/168901.htmllinuxlinuxcommand every day (21): find command xargshttp: // example (22 ): detailed description of the parameters of the find command example (23): Linux directory structure example (24): Linux file type and extension http://www.bkjia.com/ OS /201211/170431.htmleach day Li Nux command (25): linux File Attribute details http://www.bkjia.com/ OS /201211/170434.htmla linuxlinuxcommand every day (26): Use SecureCRT to upload and download the file http://www.bkjia.com/ OS /201211/172022.html chmod command to change access to 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 parameters: -- reference = <directory or File> is set to have the same permissions for the specified directory or file -- version displays version Information <permission range> + <permission setting> enables the directory or file within the permission range the file has the specified permission <permission range>-<permission settings> delete a directory or file with the specified permission range <permission range> = <permission settings> set a directory within the permission range or the permission of the file is the permission range of the specified value: u: current user g of the directory or file: current group of the directory or file o: user or group a except the current user or group of the directory or file: all users and groups have the permission code: r: Read Permission. The number 4 indicates w: write permission, the number 2 indicates x: Execution permission, and the Number 1 indicates-: delete permission, use the number 0 to indicate s: This command has special permissions 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