chgrp

>Usage

chgrp is a command used to change the group ownership of a file or directory. Groups allow users to share file access, and this command helps in changing which group owns a specific file.

>Synopsis

chgrp [option] [option]

>Options

-groupname

-groupname: Specifies the new group that will own the file.

Example 1:

Dots

-zsh

> chgrp admin file.txt


chgrp: changing group of 'file.txt': Operation not permitted

-R

-R (recursive): Changes the group ownership of all files and subdirectories within a directory.

Example 2:

Dots

-zsh

chgrp -R admin /folder


changed group of '/folder/file1' from 'group1' to 'admin'
changed group of '/folder/subdir' from 'group1' to 'admin.

--reference

--reference: Description: Changes the group ownership of the file to match the group ownership of another file.

Example 3:

Dots

-zsh

> chgrp --reference=otherfile.txt file.txt


changed group of 'file.txt' to match 'otherfile.txt'

-v

-v (verbose): Provides output for each file that is changed.

Example 4:

Dots

-zsh

> chgrp -v admin file.txt


changed group of 'file.txt' from 'group1' to 'admin'

--no-dereference

--no-dereference:Ensures symbolic links are not followed when changing the group ownership. Example:

Example 5:

Dots

-zsh

>chgrp --no-dereference admin symlink.txt


changed group of 'symlink' from 'group1' to 'admin'

-f

-f (silent):Suppresses error messages if the command fails.

Example 6:

Dots

-zsh

> chgrp -f admin file.txt


Suppresses all error messages if the command fails.

>Quiz

Progress: Question ? out of ?

Question Title

Page written by FIlippo Orlando