How to change group ownership in linux
chgrp [man page] – change group ownership
chgrp [OPTION]... GROUP FILE... chgrp [OPTION]... --reference=RFILE FILE...
3. Frequently used options in linux
-R, --recursive operate on files and directories recursively
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
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/
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/
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/
Source taken from http://linuxconfig.org/