In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the chown command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
System administrators often use the chown command to give users permission to use a file after copying it to another user's directory.
1. Command format:
The code is as follows:
Chown [options]... [owner] [: [group]] file.
2. Command function:
Change the owner and group of files through chown. You can use the user name and user identification number settings when changing the owner or group to which the file belongs. Ordinary users cannot change their files to other owners. Its operation authority is generally an administrator.
3. Command parameters:
Required parameters:
-c displays the information of the changed part
-f ignore error message
-h repair symbolic links
-R processes all files in the specified directory and its subdirectories
-v displays detailed processing information
-deference acts on the direction of the symbolic link, not on the linked file itself
Select parameters:
-- reference= takes the specified directory / file as a reference, and sets the operating file / directory to the same owner and group of the reference file / directory
-- from= changes only if the current user and group are the same as the specified user and group
-- help displays help information
-- version displays version information
4. Use an example:
Example 1: change the owner and group
Command:
The code is as follows:
Chown mail:mail log2012.log
Output:
The code is as follows:
[root@localhost test6] # ll
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 root users 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
[root@localhost test6] # chown mail:mail log2012.log
[root@localhost test6] # ll
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 mail mail 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
[root@localhost test6] #
Description:
Example 2: change file owners and groups
Command:
The code is as follows:
Chown root: log2012.log
Output:
The code is as follows:
[root@localhost test6] # ll
Total 604
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 mail mail 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
[root@localhost test6] # chown root: log2012.log
[root@localhost test6] # ll
Total 604
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 root root 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
[root@localhost test6] #
Description:
Example 3: change the file group
Command:
The code is as follows:
Chown: mail log2012.log
Output:
The code is as follows:
[root@localhost test6] # ll
Total 604
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 root root 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
[root@localhost test6] # chown: mail log2012.log
[root@localhost test6] # ll
Total 604
-xr--r-- 1 root users 302108 11-30 08:39 linklog.log
-xr--r-- 1 root mail 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users 0 11-30 08:39 log2017.log
Description:
Example 4: change the owner and group of all files under the specified directory and its subdirectories
Command:
The code is as follows:
Chown-R-v root:mail test6
Output:
The code is as follows:
[root@localhost test] # ll
Drwxr-xr-x 2 root users 4096 11-30 08:39 test6
[root@localhost test] # chown-R-v root:mail test6
The owner of "test6/log2014.log" has been changed to root:mail
The owner of "test6/linklog.log" has been changed to root:mail
The owner of "test6/log2015.log" has been changed to root:mail
The owner of "test6/log2013.log" has been changed to root:mail
The owner of "test6/log2012.log" has been retained as root:mail
The owner of "test6/log2017.log" has been changed to root:mail
The owner of "test6/log2016.log" has been changed to root:mail
The owner of "test6" has been changed to root:mail
[root@localhost test] # ll
Drwxr-xr-x 2 root mail 4096 11-30 08:39 test6
[root@localhost test] # cd test6
[root@localhost test6] # ll
Total 604
-xr--r-- 1 root mail 302108 11-30 08:39 linklog.log
-xr--r-- 1 root mail 302108 11-30 08:39 log2012.log
-rw-r--r-- 1 root mail 61 11-30 08:39 log2013.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log
-rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log
Thank you for reading! This is the end of the article on "how to use chown commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can 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.
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.