Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How linux modifies the users and groups to which the file belongs

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how linux modifies the users and groups to which the file belongs. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

In linux, you can use the chown command to modify the user and group to which the file belongs, changing the syntax of the user to "chown [- R] owner file or directory" and the syntax of the group to "chown [- R]: group file or directory.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

In Linux, when you create a file, the owner of the file is the user who created the file. The user of the file can modify the owner and user group of the file, or under root users, this can modify the owner and user group of any file.

The chown command is needed to modify the users and groups to which the file belongs.

The chown command, which can be thought of as an abbreviation for "change owner", is mainly used to modify the owner of the file (or directory). In addition, this command can also modify the group to which the file (or directory) belongs.

When you only need to change the owner, you can use the basic format of the following chown command:

Chown [- R] owner file or directory

The-R (note uppercase) option means that all files in the subdirectory are changed owners.

When you only need to modify the group you belong to, you can use the basic format of the following chown command:

Chown [- R]: group file or directory to which it belongs

If you need to change both the owner and the group to which you belong, the basic format of the chown command is:

Chown [- R] owner: group file or directory to which it belongs

Note that in the chown command, a dot (.) can also be used between the owner and the group to which it belongs, but there is a problem that if the user adds a decimal point (such as zhangsan.temp) when setting the account, it will cause the system to misjudge. Therefore, it is recommended that you use colons to connect the owner and the group to which you belong.

Of course, the chown command also supports simply modifying the group to which the file or directory belongs. For example, chown: group install.log means to modify the group to which the install.log file belongs, but the group to which it belongs usually uses the chgrp command, so it is not recommended to use the chown command.

Another point to note is that when you use the chown command to modify the owner (or owner) of a file or directory, make sure that the user user (or user group) exists, otherwise the command cannot be executed correctly and will prompt "invalid user" or "invaild group".

An example of using the chown command

1. Change the owner of the file

First, let's use the ls-l command to check the ownership of the file, for example:

# ls-l tmpfile-rw-r-r-- 1 himanshu family 0 2019-03-30 11:03 tmpfile

Let's use the chown command to change the owner of the tmpfile file

# chown root tmpfile

Then use the ls-l command to check the ownership of the tmpfile file

# ls-l tmpfile-rw-r-r-- 1 root family 0 2019-03-30 11:04 tmpfile

It can be seen that the owner of the tmpfile file, bug "himanshu", has become "root".

2. Change the filegroup

You can also change the group (the group to which the file belongs) through the chown command.

Use the following command to change the group to which the file belongs:

# chown: root tmpfile

Then use the ls-l command to check the ownership of the tmpfile file

# ls-l tmpfile-rw-r-r-- 1 root root 0 2019-03-30 11:04 tmpfile

You can also directly change the owner and group of the file to root at one time, using the following command:

# chown root:root tmpfile's article on "how to modify the users and groups to which linux belongs" ends here. I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report