English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Linux chgrp (full English name: change group) command is used to change the group ownership of files or directories.
With chown Different commands, chgrp allows ordinary users to change the group ownership of files, as long as the user is a member of that group.
In the UNIX system family, the control of file or directory permissions is managed by the owner and the group. You can use the chgrp command to change the group ownership of files and directories, which can be done by group name or group ID.
chgrp [-cfhRv][--help][--version][Group][File or directory...] or chgrp [-cfhRv][--help][--reference=<reference file or directory>][--version][File or directory...]
-c or--The effect is similar to ""-The "parameter" returns only the changed parts.
-f or--quiet or--silent Do not display error information.
-h or--no-dereference Only modify the files of symbolic links, without changing any other related files.
-R or--recursive Recursively process, and handle all files and subdirectories under the specified directory.
-v or--verbose Show the execution process of the command.
--help Online help.
--reference=<reference file or directory> Set the group ownership of the specified file or directory to the same as the reference file or directory.
--version Show version information.
Example1Change the group attribute of the file:
chgrp -v bin log2012.log
Output:
[root@localhost test]# ll ---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log [root@localhost test]# chgrp -v bin log2012.log
"log2012The group of .log" has been changed to bin
[root@localhost test]# ll ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log
Note: Change log2012The .log file is changed from the root group to the bin group
Example2Change the group attribute of the specified file
chgrp --reference=log2012.log log2013.log
Output:
[root@localhost test]# ll ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log -rw-r--r-- 1 root root 61 11-13 06:03 log2013.log [root@localhost test]# chgrp --reference=log2012.log log2013.log [root@localhost test]# ll ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log -rw-r--r-- 1 root bin 61 11-13 06:03 log2013.log
Note: Change the file log2013The group attributes of .log make the file log2013The group attributes of .log and the reference file log2012The group attributes of .log are the same