Summary of usage of Linux chmod commands

  
                

In the Linux command, the usage of the chmod command is somewhat similar to that of the chattr command, but the chmod command only changes the file read and write and execute permissions. The file permissions are mainly completed by the chattr command. The following small series will introduce you to the following. The use of the chmod command in Linux.

access to the file or directory is divided into read-only, write-only, and can perform three. In the case of a file, read-only permission means that only its contents are allowed to be read, and any changes are prohibited. Executable permissions indicate that the file is allowed to execute as a program. When a file is created, the file owner automatically has read, write, and executable permissions on the file to facilitate reading and modifying the file. Users can also set access rights to any combination they need, as needed.

There are three different types of users that can access files or directories: file owners, groups of users, and other users. The owner is usually the creator of the file. The owner can allow the same group of users to have access to the file, and can also give access to the file to other users in the system. In this case, every user in the system can access the files or directories owned by the user.

There are three groups of access rights for each file or directory, each group is represented by three digits, which are the read, write and execute permissions of the file owner; the read and write of the user in the same group as the owner Execute permissions; read, write, and execute permissions for other users in the system. When using the ls -l command to display the details of a file or directory, the leftmost column is the file's access rights. For example:

Command:

The code is as follows:

ls -al

Output:

The code is as follows:

[root@localhost test]# ll -al

Total 316lrwxrwxrwx 1 root root 11 11-22 06:58 linklog.log -> log2012.log

-rw-r--r -- 1 root root 302108 11-13 06:03 log2012.log

-rw-r--r-- 1 root root 61 11-13 06:03 log2013.log

- Rw-r--r-- 1 root root 0 11-13 06:03 log2014.log

-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log< Br>

-rw-r--r-- 1 root root 0 11-16 14:41 log2016.log

-rw-r--r-- 1 root root 0 11-16 14 :43 log2017.log

Let's take log2012.log as an example:

The code is as follows:

-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

The first column has 10 locations, the first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it means a non-directory file. If it is d, it means a directory. From the second character to the tenth total of 9 characters, a set of three characters, respectively, indicates the permissions of three groups of users on files or directories. The permission characters use horizontal lines to represent empty permissions, r to read only, w to write, and x to be executable.

For example:

The code is as follows:

- rw- r-- r--

means that log2012.log is a normal file; log2012.log The owner has read and write permissions; users with the same group as log2012.log have read permissions; other users have read permissions only.

After determining the access rights of a file, users can use the chmod command provided by the Linux system to reset different access rights. 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 rights of a file or directory. The user uses it to control access to files or directories. The details of the chmod command are as follows.

1. Command format:

The code is as follows:

chmod [-cfvR] [--help] [--version] mode file

2 Command function:

Used to change the access rights of a file or directory, and use it to control the access rights of a file or directory.

3. Command parameters:

Required parameters:

-c Report processing information when a change occurs

-f Error message does not output

-R Processes all files in the specified directory and its subdirectories

-v Displays detailed processing information at runtime

Select parameters:

--reference= "Directory or file" is set to have the specified directory or the file has the same permissions

--version Display version information

"Right Scope" + "Permission Settings" Make the directory within the scope of the permission or The file has the specified permissions

"Scope of Permissions" - "Permission Settings" Delete the directory of the permission range or the specified permissions of the file

"Scope of Permissions" = "Permission Settings" The permissions of the directory or file are the specified values
Previous123Next page Total 3 pages

Copyright © Windows knowledge All Rights Reserved