Linux Common Commands 30:chgrp command

Source: Internet
Author: User

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.

command Format

CHGRP [Options] [group] [file]

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.

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

Common 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

Real 2: Change the group properties of the file according to the 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

 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 Common Commands 30:chgrp command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.