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 example shares the specific code of ...
Note: This demo is tested in the mini program env...
In tomcat, jsp is not garbled, but html Chinese i...
Effect html <body> <div class="cont...
Adding the right VS Code extension to Visual Stud...
Preface The simple understanding of MySQL permiss...
Table of contents Normal paging query How to opti...
Preface As we all know, "How to vertically c...
We usually have a scanning box when we open the c...
Preface In web applications, in order to save tra...
Table of contents 1. Simple to use 2. Use DISTINC...
This article example shares the specific code for...
Preface A reverse proxy is a server that receives...
What is a file system We know that storage engine...
KILL [CONNECTION | QUERY] processlist_id In MySQL...