Linux basic command-chgrp
Chgrp
Change the group to which the file or directory belongs. Use the parameter "--reference" to change the file group to the specified associated file group. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Chgrp [options] group file
Chgrp [options]-reference=RFILE file
2. List of options
Option
Description
-- version
Display command version information
-- help
Show help documentation
-c |-- changes
Same as verbose, but only show details when a change occurs
-- dereference
Change the file that the symbolic link points to, not the symbolic link itself. This is the default option
-h |-- no-dereference
Modify symbolic links, only for systems that can change symbolic link ownership
-- no-preserve-root
No special treatment "/", default option
-- preserve-root
Failed to perform recursive operation on "/"
-f |-- silent |-- quiet
Ignore some error messages
-- reference=file
Use the group to which the associated file belongs instead of pointing to a specific value
-R,-- recursive
Recursively process directories and their internal files
-v |-- verbose
Show details
-H
If the command line argument is a symbolic link to the directory, traverse it. Use with "- R"
-L
Traverse each symbolic link to the directory encountered. Use with "- R"
-P
Do not traverse any symbolic links (default). Use with "- R"
3. Example-
1) modify the group to which the file belongs
[root@localhost weijie] # ls-l / / use ls to view details
The total dosage is 1072
-rw-r--r-- 1 root root 7 September 09:11 1.c
-rw-r--r-- 3 root root 358400 September 7 15:46 link
[root@localhost weijie] # chgrp weijie 1.c / / modify the group
[root@localhost weijie] # ls-l / / check again, the modification has been successful
The total dosage is 1072
-rw-r--r-- 1 root weijie 7 September 09:11 1.c
-rw-r--r-- 3 root root 358400 September 7 15:46 link
2) use the option "--reference"
[root@localhost weijie] # chgrp-- reference=1.c my.iso / / 1.c 's group is already weijie
[root@localhost weijie] # ls-l
The total dosage is 1072
-rw-r--r-- 1 root weijie 7 September 09:11 1.c
-rw-r--r-- 3 root weijie 358400 September 7 15:46 my.iso / / my.iso group also becomes wiejie
3) modify only symbolic links themselves
[root@localhost wj] # ls-l 1.c 11.c / / View file information
Lrwxrwxrwx 1 root root 3 October 26 10:11 11.c-> 1.c
-rw-r--r-- 1 root root 0 October 24 10:12 1.c
[root@localhost wj] # chgrp-h weijie 11.c / / modify the group
[root@localhost wj] # ls-l 1.c 11.c / / View file information, only symbolic links have their own groups modified
Lrwxrwxrwx 1 root weijie 3 October 26 10:11 11.c-> 1.c
-rw-r--r-- 1 root root 0 October 24 10:12 1.c