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
Table of contents question Solution question Ther...
See: https://www.jb51.net/article/112612.htm Chec...
This article shares the specific code of jQuery t...
Introduction to Dockerfile Docker can automatical...
When shutting down the MySQL server, various prob...
Preface The server system environment is: CentOS ...
Some time ago, the project needed to develop the ...
When inserting a set of data into the MySQL datab...
It is very convenient to connect to a remote serv...
Here 123WORDPRESS.COM presents the first part of ...
After installing VMware and creating a new virtua...
WebRTC, which stands for Web Real-Time Communicat...
1. Docker network management 1. Docker container ...
Preface In JavaScript, this is the function calli...
NProgress is the progress bar that appears at the...