In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Linux how to change file or directory access", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Linux how to change file or directory access" this article.
Files and directories in the Linux system have access permissions to determine who can access and manipulate files and directories in what way.
Permissions are divided into read-only, write-only and executable.
In the case of a file, for example, read-only permission means that only its contents are allowed to be read, and any changes to it are prohibited.
Executable permissions allow the file to be executed as a program.
When a file is created, the file owner automatically has read, write, and executable permissions to the file to facilitate reading and modification of the file.
There are three types of access to a file or directory: file owner, user in the same group, and other users.
The owner is generally the creator of the file. The owner can allow the same group of users to have access to the file, and can also grant 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 that user.
There are three groups of access permissions for each file or directory, and each group is represented by three digits, which are:
Read, write, and execute permissions of the owner of the file
Read, write, and execute permissions of users in the same group
Read, write, and execute permissions of other users in the system.
When you use the ls-l command to display the details of a file or directory, the leftmost column lists the access permissions for the file. For example:
$ls-l source.tgz-rw-r-r- 1 root root 483997 Ju1 l5 17 rw-r-r- 31 source.tgz
The horizontal line represents an empty license. R stands for read-only, w for write, and x for executable. Notice that there are 10 locations here. The first character specifies the file type. If it's d, it means it's a directory.
For example:
-rw- r-r-
Normal file main group users other users
The above indicates that source.tgz is an ordinary file; the owner of source.tgz has read and write permission; users in the same group as source.tgz only have read permission; and other users only have read permission.
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.
These commands are described below.
Chmod command
Used to change the access permissions of a file or directory. Users use it to control access to files or directories.
This command has two uses. One is a text setting method that contains letters and operator expressions; the other is a numeric setting method that contains numbers.
1. Character setting method
Chmod [who] [+ |-| =] [mode] file name
The commonly used-R parameter indicates a recursive change of permissions. Contains all folders and files under the word directory
two。 Digital setting method
We must first understand the meaning of numeric attributes: 0 indicates no permission, 1 indicates executable permission, 2 indicates read permission, and 4 indicates write permission.
And then add it up. So the format of the numeric attribute should be 3 octal numbers from 0 to 7, in the order of (user) (group) (other) the combination of three user types.
For example, if you want the owner of a file to have read / write permissions, you need to put 4 (readable) + 2 (writable) = 6 (read / write).
The general form of digital setting method is:
Chmod [mode] file name
Chgrp command
Function: change the group to which the file or directory belongs.
Syntax: chgrp [options] group filename
This command changes the user group to which the specified file belongs. Where group can be the user group ID or the group name of the user group in the / etc/group file. The file name is a list of files to be changed to the group separated by spaces, and wildcards are supported. If the user is not the owner or superuser of the file, you cannot change the group of the file.
The options of this command mean:
-R recursively changes the grouping of the specified directory and all subdirectories and files under it.
Chown command
Function: change the owner and group of a file or directory.
For example, the root user copies one of his files to the user xu. In order to enable the user xu to access the file, the root user should set the owner of the file to xu, otherwise, the user xu cannot access the file.
Syntax: chown [options] user or group files
Description: chown changes the owner of the specified file to the specified user or group. The user can be a user name or user ID. A group can be a group name or a group ID. Files are a list of files to change permissions separated by spaces, and wildcards are supported.
The options for this command mean the following:
-R recursively changes the owner of the specified directory and all subdirectories and files under it. -v shows the work done by the chown command.
The operation symbol can be:
+ add a permission. -revoke a permission. = Grant the given permission and cancel all other permissions, if any.
The permissions represented by mode can be set with any combination of the following letters:
R is readable. W is writable. X is executable.
X appends the x attribute only if the target file is executable to some users or if the target file is a directory.
File name: a list of files to change permissions separated by spaces. Wildcards are supported.
Multiple permissions can be given on a command line, separated by commas. For example: chmod gendarmerie Odysr example
Make the same group and other users have read permission to the file example.
The above is all the contents of the article "how to change the access to a file or directory by Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.