How to use the Linux chown command


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!

1. Command Introduction

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'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.

2. Example

1. Get command help

[root@s141 home]# chown --help

2. View command version

[root@s141 home]# chown --version
chown (GNU coreutils) 8.22
Copyright © 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.< br/>There is NO WARRANTY, to the extent permitted by law.

Written by DavidMacKenzie and Jim Meyering.

3. Modify file owner and group

[root@s141 test]# touch 1.txt
[root@s141 test]# ll
total 0
-rw-r–r-- 1 root root 0 Nov 22 15:52 1.txt
drwxrwxr-x 2 test test 6 Nov 21 18:24 a
[root@s141 test]# chown test.test 1.txt
[root@s141 test]# ll
total 0
-rw-r– r-- 1 test test 0 Nov 22 15:52 1.txt
drwxrwxr-x 2 test test 6 Nov 21 18:24 a

4. Recursively modify the entire directory Master group

5. Modify the link owner group

6. Modify the group, the owner is reserved

7. Display modification information


8. L and H parameter test

3. Usage syntax and parameter description
1. Usage syntax

Usage: chown [parameter] user[:group] file

2. Parameter Description
Display detailed processing information
ParameterParameter Description
userUser ID of the new document owner
groupUser group of the new document owner (group)
-cDisplay the information of the changed part
-fignore error messages
-hfix symlinks
-RProcess the specified directory and its childrenAll files in the directory
–helpDisplay auxiliary instructions
--versionDisplay version
3. Traverse parameter description

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.

  • -H If the command line argument is a symbolic link to a directory, traverse it

  • -L Traverse each symlinks to directories

  • -P Do not traverse any symlinks (default)

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