Contents[Hide]

1. Name

chgrp [man page] - change group ownership

2. Synopsis

chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...

3. Frequently used options

-R, --recursive
operate on files and directories recursively

4. Examples

Let's first create same sample directories in /tmp to test chgrp command. The following mkdir command will create two directories: directory1 and directory2 where directory1 is a parent of directory2.

# cd /tmp
# mkdir -p directory1/directory2

chgrp create directories
Next we can also create a file in /tmp/directory1/directory2

# touch /tmp/directory1/directory2/file
# ls -ld /tmp/directory1/directory2/
# ls -l directory1/directory2/

chgrp create file
At this stage as we can see that group ownership is assigned to a root for both directories and file. To change an ownership of directory1 to linuxconfig group we can enter command:

NOTE: the group must exists in order to take ownership of a file or directory

# chgrp linuxconfig /tmp/directory1/
# ls -ld /tmp/directory1/
# ls -ld /tmp/directory1/directory2/

change ownership of directory
The group ownership of directory1 has been changed to linuxconfig. To change a group ownership of directory2 and a file within a directory2 we need to use a chgrp's recursive options -R.

# chgrp -R linuxconfig /tmp/directory1/
# ls -ld /tmp/directory1/
# ls -ld /tmp/directory1/directory2/
# ls -l /tmp/directory1/directory2/

change group ownership of directory and file

Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top