In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the role of the chown command in linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
In linux, the chown command is used to change the owner of a file or directory and the group to which it belongs. This command can authorize a user to become the owner of a specified file or change the group to which the file belongs; the syntax for this command is "chown [option]... [owner] [: [group]] file."
The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.
Linux chown command
The chown command changes the owner and group to which a file or directory belongs, and it can authorize a user to become the owner of a specified file or to change the group to which the file belongs. The user can be a user or user D, and the user group can be a group name or a group id. File names can make a list of files separated by spaces, and wildcards can be included in the file name.
Only file owners and superusers can use this command.
Command format:
Chown [options]... [owner] [: [group]] file. 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.
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
Examples of use:
Example 1: change the owner and group
Command:
Chown mail:mail log2012.log output:
[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 -log2013.log-rw-r--r-- 1 root users 0 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] # instance 2: change file owners and groups
Command:
Chown root: log2012.log output:
[root@localhost test6] # ll Total 604 root users 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 Khokuhashi-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] #
Example 3: change the file group
Command:
Chown: mail log2012.log output:
[root@localhost test6] # ll Total 604 root users 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 Khokuhashi-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
Example 4: change the owner and group of all files under the specified directory and its subdirectories
Command:
Chown-R-v root:mail test6 output:
[root@localhost test] # lldrwxr-xr-x 2 root users 4096 11-30 08:39 test6 [root@localhost test] # chown-R-v root:mail test6 "test6/log2014.log" owner has been changed to root:mail "test6/linklog.log" owner has been changed to root:mail "test6/log2015.log" owner has been changed to root:mail "test6/log2013.log" owner has been changed to root:mail "test6/log2012 The owner of the .log "has been retained as the owner of root:mail" test6/log2017.log "has been changed to the owner of root:mail" test6/log2016.log "has been changed to root:mail" test6 "the owner has been changed to root:mail [root@localhost test] # lldrwxr-xr-x 2 root mail 4096 11-30 08:39 test6 [root@localhost test] # cd test6 [root@localhost test6] # ll Total 604Kuk XRMW 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 on "the role of chown commands in linux" ends here Hope that 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.
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.