In the LUnix system, the control of the permissions of a file or directory is managed by the owner and the group being sued. You can use the CHGRP command to change the file and directory to belong to the group, this way with the group name or group identification code can be. The CHGRP command is the abbreviation for change Group! The group name to be changed must exist within the/etc/group file.
1. Command format:
CHGRP [Options] [group] [file]
2. Command function:
The CHGRP command can change the group that the file or directory belongs to by using a group name or a group identifier. The usage permission is superuser.
3. Command parameters:
Necessary parameters:
-C Output Debug information when a change occurs
-F does not display error messages
-R handles all files in the specified directory and its subdirectories
-V Run-time display verbose processing information
--dereference acts on the point of a symbolic link, not the symbolic link itself
--no-dereference acting on the symbolic link itself
Select parameters:
--reference=< files or Directories >
--HELP Display Help information
--version displaying version information
4. Usage examples:
Example 1: Changing the group properties of a file
Command:
Chgrp-v bin Log2012.log
Output:
[email protected] test]# LL
---xrw-r--1 root root 302108 11-13 06:03 log2012.log
[Email protected] test]# Chgrp-v bin Log2012.log
The owning group for "Log2012.log" has changed to Bin
[email protected] test]# LL
---xrw-r--1 root bin 302108 11-13 06:03 log2012.log
Description
Change the Log2012.log file from the root group to the bin group
Example 2: Changing the group properties of a file according to a specified file
Command:
Chgrp--reference=log2012.log Log2013.log
Output:
[email protected] test]# LL
---xrw-r--1 root bin 302108 11-13 06:03 log2012.log
-rw-r--r--1 root root 11-13 06:03 Log2013.log
[Email protected] test]# chgrp--reference=log2012.log log2013.log
[email protected] test]# LL
---xrw-r--1 root bin 302108 11-13 06:03 log2012.log
-rw-r--r--1 Root bin 11-13 06:03 Log2013.log
Description
Change the group properties of the file Log2013.log to make the group properties of the file Log2013.log the same as the group properties of the reference file Log2012.log
Example 3: Changing the group properties of the specified directory and all files under its subdirectories
Command:
Output:
[email protected] test]# LL
Drwxr-xr-x 2 root root 4096 11-30 08:39 Test6
[Email protected] test]# CD TEST6
[email protected] 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 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
[Email protected] test6]# CD.
[Email protected] test]# Chgrp-r bin Test6
[Email protected] test]# CD TEST6
[email protected] 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 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
[Email protected] test6]# CD.
[email protected] test]# LL
Drwxr-xr-x 2 root bin 4096 11-30 08:39 Test6
[Email protected] test]#
Description
Changes the group properties of the specified directory and all files under its subdirectories
Example 4: Changing file group properties by group ID
Command:
Chgrp-r Test6
Output:
[Email protected] test]# chgrp-r TEST6
[email protected] test]# LL
Drwxr-xr-x 2 root users 4096 11-30 08:39 Test6
[Email protected] test]# CD TEST6
[email protected] 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 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
[Email protected] test6]#
Description
Group identification code to change the file group properties, 100 for the Users group identification code, specific groups and group identification code can go to/etc/group file to view
Linux command (*): chgrp command