In Linux, when a file is created, the owner of the file is the user who creates the file. The file user can modify the owner and user group of the file; or under the root user, the owner and user group of any file can be modified. To modify the user and group to which a file belongs, you need to use the chown command. The chown command, which can be considered as the abbreviation of "change owner", is mainly used to change the owner of a file (or directory). In addition, this command can also change the group to which a file (or directory) belongs. When you only need to change the owner, you can use the following basic format of the chown command: chown [-R] owner of a file or directory
When you only need to change the group, you can use the following basic format of the chown command: chown [-R]: group file or directory If you need to change both the owner and the group, the basic format of the chown command is: chown [-R] owner:group file or directory Note that in the chown command, a dot (.) can be used between the owner and the group, but this will cause a problem. If the user adds a decimal point when setting the account (for example, zhangsan.temp), the system will misjudge it. Therefore, it is recommended that you use a colon to connect the owner and the group. Of course, the chown command also supports simply modifying the group to which a file or directory belongs. For example, chown :group install.log means modifying the group to which the install.log file belongs. However, the chgrp command is usually used to modify the group to which the file belongs, so it is not recommended to use the chown command. Another point to note is that when using the chown command to modify the owner (or owner) of a file or directory, you must ensure that the user (or user group) exists. Otherwise, the command cannot be executed correctly and will prompt "invalid user" or "invaild group". Examples of using the chown command1. Change the owner of the file First, we use the ls -l command to check the ownership of the file, for example: #ls -l tmpfile -rw-rr-- 1 himanshu family 0 2019-03-30 11:03 tmpfile Next, we use the chown command to change the owner of the tmpfile file. #chown root tmpfile Then use the ls -l command to check the owner of the tmpfile file. #ls -l tmpfile -rw-rr-- 1 root family 0 2019-03-30 11:04 tmpfile It can be seen that the owner of the tmpfile file has changed from "himanshu" to "root" 2. Change the file group The group (the group to which the file belongs) can also be changed through the chown command. Use the following command to change the group to which a file belongs: #chown :root tmpfile Then use the ls -l command to view the owner of the tmpfile file #ls -l tmpfile -rw-rr-- 1 root root 0 2019-03-30 11:04 tmpfile You can also change the owner and group of the file to root at one time by using the following command: #chown root:root tmpfile This is the end of this article about the practical method of modifying the user and group to which a file belongs in Linux. For more information on how to modify the user and group to which a file belongs in Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Metadata Extraction Example Analysis of MySQL and Oracle
>>: Tips for implementing multiple borders in CSS
This article shares the specific code of fabricjs...
Preface When using RabbitMQ, if there is no traff...
1. Introduction In the past, if you wanted to sta...
Preface The so-called fuzzy query is to provide q...
1. Explanation of provide and inject Provide and ...
Solve the problem that the responseText returned ...
Table of contents Preface Global Lock Table lock ...
Using the <img> element with the default sr...
This article shares the detailed steps of install...
TABLE> <TR> <TD> <TH> <CA...
This article uses the "Attribution 4.0 Inter...
DCL (Data Control Language): Data control languag...
Table of contents Main issues solved 1. The data ...
My first server program I'm currently learnin...
Table of contents Install: 1. Basic use of firewa...