Linux Base command (CHGRP command)

Source: Internet
Author: User
Tags reference

In a LUnix system, the authority of a file or directory is managed by the owner and the group in which it is sued. You can use the CHGRP instruction to change the file to the group that the directory belongs to, either by group name or group identification code. The CHGRP command is the abbreviation for 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 change the group of files or directories by group name or group identifier. Use permissions are superuser.

3. Command parameters:

Necessary parameters:

-C output debugging information when a change occurs

-F does not display error messages

-R handles all files in the specified directory and its subdirectories

-V Runtime displays detailed processing information

--dereference the point of the symbolic link, not the symbolic link itself.

--no-dereference acts on the symbolic link itself

Select parameters:

--reference=< file or directory >

--HELP Display Help information

--version Display version Information

4. Use instance:

Example 1: Changing the group properties of a file

Command:

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 owning group for "Log2012.log" has changed to Bin

[Root@localhost test]# LL

---xrw-r--1 root bin 302108 11-13 06:03 log2012.log

Description

Change Log2012.log file from root group to bin Group

Example 2: Changing the group properties of a file based on a specified file

Command:

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 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 11-13 06:03 Log2013.log

Description

Change the group properties of the file Log2013.log so that the group attributes of the file Log2013.log are the same as the group attributes of the reference file Log2012.log

Example 3: Change the group properties of the specified directory and all files under its subdirectories

Command:

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 11-30 08:39 log2013.log

-rw-r--r--1 root 0 11-30 08:39 log2014.log

-rw-r--r--1 root 0 11-30 08:39 log2015.log

-rw-r--r--1 root 0 11-30 08:39 log2016.log

-rw-r--r--1 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 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]#

Description

Changes the group properties of the specified directory and all files under its subdirectories

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.