Insight: Practical Examples Of chgrp Command In Linux [Beginner’s Guide]
chgrp command stands for change group ownership. It is related to the file permission related job in Linux operating system. In this post, we will talk about some of the practical examples of chgrp command in Linux operating system.
chgrp command is a easy to learn and easy to use command in Linux. chgrp is simple to use compared to chown for the the job of changing group ownership of the file or directory.
chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE.
chgrp [options] groupname file >
Practical Examples Of chgrp Command In Linux [Begineer’s Guide]
1. Change the group name of a file or directory
In the command below, group ownership of sample.txt is changed to hope group.
chgrp hope sample.txt
In the command below, Owning group of /office/files, and all subdirectories is changed to the group staff.
chgrp -hR staff /office/files
2. Change the group name of link files.
Use the following command to change the group name of link files.
# the group name of actual file pointed by sym_link gets changed. $ chgrp --dereference guest sym_link # the group name of sym_link gets changed. $ chgrp --no-dereference user sym_link $ ls -l sym_link omgfoss_sample.txt lrw-r--r-- 1 omgfoss user 4 2018-05-04 10:52 sym_link -> sample.txt -rw-r--r-- 1 omgfoss guest 20 2018-05-04 10:52 sample.txt
3. Change the group for list of the files
Use the -R option, you can change the group for list of the files.
$ chgrp -R guest dir/ $ ls -l dir/ total 11 -rw-r--r-- 1 omgfoss guest 20 2018-09-25 16:50 sample.txt -rw-r--r-- 1 omgfoss guest 20 2018-09-25 16:50 samplenew.txt
3. Print the verbose messages only when changes are made
The -c option makes the verbose messages gets printed when changes has been made to the FILE.
$ chgrp -c user sample.txt changed group of `sample.txt' to user