Home > Hosting > Server

How to use the Linux chown command

2023-06-06 10:24:22

<p style="text-align: left;">This article mainly introduces how to use the Linux chown command. In daily operations, I believe many people have doubts about how to use the Linux chown command. I hope it will be helpful for you to answer your doubts about how to use the Linux chown command! Next, please follow the editor to learn together!</p><p><br/></p><h4 style="text-align: left;">1. Command Introduction</h4><p style="text-align: left;">Linux chown (English spelling: change owner) command is used to set the file owner and file association group command, chown The privileges of the superuser root are required to execute this command. chown changes the user and/or group ownership of each given file. If only an owner (username or numeric user ID) is provided, that user will become the owner of each given file and the filegroup will not be changed. If owner is followed by a colon and the group name (or numeric group ID) without a space in between, the group ownership of the file is also changed. If there is a colon after the user name, but no group name, the user becomes the owner of the file and the file group is changed to the user&#39;s login group. If a colon and group are given but owner is omitted, only the file group is changed; in this case chown performs the same function as chgrp. If only a colon is given, or if the entire operand is empty, the owner or group has changed.</p><h4 style="text-align: left;">2. Example</h4><h5 style="text-align: left;">1. Get command help</h5><blockquote style="text-align: left;"><p style="text-align: left;">[root@s141 home]# chown --help</p><h5 style="text-align: left;">2. View command version</h5><blockquote><p style="text-align: left;">[root@s141 home]# chown --version<br/>chown (GNU coreutils) 8.22<br/>Copyright © 2013 Free Software Foundation, Inc.<br/>License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.<br/>This is free software: you are free to change and redistribute it.&lt; br/&gt;There is NO WARRANTY, to the extent permitted by law.<br/><br/>Written by DavidMacKenzie and Jim Meyering.</p></blockquote><h5 style="text-align: left;">3. Modify file owner and group</h5><blockquote><p style="text-align: left;">[root@s141 test]# touch 1.txt<br/> [root@s141 test]# ll<br/>total 0<br/>-rw-r–r-- 1 root root 0 Nov 22 15:52 1.txt<br/>drwxrwxr-x 2 test test 6 Nov 21 18:24 a<br/>[root@s141 test]# chown test.test 1.txt<br/>[root@s141 test]# ll<br/>total 0<br/>-rw-r– r-- 1 test test 0 Nov 22 15:52 1.txt<br/>drwxrwxr-x 2 test test 6 Nov 21 18:24 a</p></blockquote><h5 style="text-align: left;">4. Recursively modify the entire directory Master group</h5><p><br/></p><h5 style="text-align: left;">5. Modify the link owner group</h5><p><br/></p><h5 style="text-align: left;">6. Modify the group, the owner is reserved</h5><p><br/></p><h5 style="text-align: left;">7. Display modification information</h5><p style="text-align: left;"><img src="//img.freeonlinedomain.com/uploads/allimg/20230608/1-23060Q1153Y91.jpg" title="" alt="1.jpg"/></p><h5 style="text-align: left;">8. L and H parameter test</h5><p><br/></p>3. Usage syntax and parameter description<h5>1. Usage syntax</h5><blockquote><p>Usage: chown [parameter] user[:group] file</p></blockquote><h5>2. Parameter Description</h5>Display detailed processing information<table><tbody><tr class="firstRow"><th>Parameter</th><th>Parameter Description</th></tr><tr><td>user</td><td>User ID of the new document owner</td></tr><tr><td>group</td><td>User group of the new document owner (group)</td></tr><tr><td>-c</td><td>Display the information of the changed part</td></tr><tr><td>-f</td><td>ignore error messages</td></tr><tr><td>-h</td><td>fix symlinks</td></tr><tr><td>-v</td><td><br/></td></tr><tr><td>-R</td><td>Process the specified directory and its childrenAll files in the directory</td></tr><tr><td>–help</td><td>Display auxiliary instructions</td></tr><tr><td>--version</td><td>Display version</td></tr></tbody></table><h5>3. Traverse parameter description</h5><p>The following options are modified when the -R option is also specified Ways to traverse the hierarchy. If more than one is specified, only the last one takes effect.</p><ul class=" list-paddingleft-2"><li><p>-H If the command line argument is a symbolic link to a directory, traverse it</p></li><li><p>-L Traverse each symlinks to directories</p></li><li><p>-P Do not traverse any symlinks (default)</p></li></ul><p><br/></p></blockquote>


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us