In the lunix system, the control of the permissions of a file or directory is managed by the owner and the group referred to. You can use the chgrp command to get the group to which the changed files and directories belong. This method can use either the group name or the group ID. Chgrp command is the abbreviation of change group! The group name to be changed must exist in the /etc/group file.
1. Command format:
chgrp [options] [group] [file]
2. Command function:
The chgrp command can use the group name or group ID to change the group to which the file or directory belongs. Access is superuser.
3. Command parameters:
Required parameters:
-c output debug info when changed
-f do not display error messages
-R Process all files in the specified directory and its subdirectories
-v display detailed processing information when running
--dereference acts on the symlink pointing to, not the symlink itself
--no-dereference acts on the symlink itself
Select parameters:
--reference=<file or directory>
--help display help information
--version display version information
4. Example of use:
Example 1: Change the group attribute of a file
Order:
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 The group of "log2012.log" has been changed to bin [root@localhost test]# ll --- xrw-r-- 1 root bin 302108 11 - 13 06 : 03 log2012.log
illustrate:
Change the log2012.log file from the root group to the bin group
Example 2: Change the group attribute of the file according to the specified file
Order:
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
illustrate:
Change the group attribute of the file log2013.log so that the group attribute of the file log2013.log is the same as the group attribute of the reference file log2012.log
Example 3: Change the group attribute of all files in the specified directory and its subdirectories
Order:
output:
[root@localhost test]# ll drwxr-xr-x 2 root root 4096 11-30 08:39 test6 [root@localhost test]# cd test6 [root@localhost test6]# ll ---xr--r-- 1 root root 302108 11-30 08:39 linklog.log ---xr--r-- 1 root root 302108 11-30 08:39 log2012.log -rw-r--r-- 1 root root 61 11-30 08:39 log2013.log -rw-r--r-- 1 root root 0 11-30 08:39 log2014.log -rw-r--r-- 1 root root 0 11-30 08:39 log2015.log -rw-r--r-- 1 root root 0 11-30 08:39 log2016.log -rw-r--r-- 1 root root 0 11-30 08:39 log2017.log [root@localhost test6]# cd .. [root@localhost test]# chgrp -R bin test6 [root@localhost test]# cd test6 [root@localhost test6]# ll ---xr--r-- 1 root bin 302108 11-30 08:39 linklog.log ---xr--r-- 1 root bin 302108 11-30 08:39 log2012.log -rw-r--r-- 1 root bin 61 11-30 08:39 log2013.log -rw-r--r-- 1 root bin 0 11-30 08:39 log2014.log -rw-r--r-- 1 root bin 0 11-30 08:39 log2015.log -rw-r--r-- 1 root bin 0 11-30 08:39 log2016.log -rw-r--r-- 1 root bin 0 11-30 08:39 log2017.log [root@localhost test6]# cd .. [root@localhost test]# ll drwxr-xr-x 2 root bin 4096 11-30 08:39 test6 [root@localhost test]#
illustrate:
Change the group attribute of all files in the specified directory and its subdirectories
Example 4: Change file group attributes by group ID
Order:
chgrp -R 100 test6
output:
[root@localhost test]# chgrp -R 100 test6 [root@localhost test]# ll drwxr-xr-x 2 root users 4096 11-30 08:39 test6 [root@localhost test]# cd test6 [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]#
illustrate:
Change the file group attribute through the group identification code, 100 is the identification code of the users group, the specific group and group identification code can be viewed in the /etc/group file