Changing Groupownership of Files in Linux(chgrplinux)

In Linux, file or folder owner and group have permissions to read, write and execute the files. These permissions can be changed to provide appropriate access to the files or folders. The same concept also applies to changing the ownership of the group of files.

Changing the ownership of a group of files can be done quite easily in linux via commandline. Only the user with root privileges can make changes in group ownership of files in Linux. Consequently, first you need to switch to root user with the following command:

`su root`

After switching to root user, navigate to the directory containing the files whose group ownership needs to be updated. Use the following command to change the group ownership of all the files in the working directory to a particular group:

`chgrp -R groupname `

Here, groupname is the REPLACE ME with the name of the group to which the files needs to be assigned. The -R switch helps to recursively change the permissions for the contents of a folder and all its subfolders or files.

For example, if the current working directory is “/home/mydir” and it has a bunch of files and subdirectories. Then making a group named “testgroup” as the owner for all the files and subdirectories of this directory, the following command should be used:

`$ chgrp -R testgroup /home/mydir `

Finally, verify the group ownership of all the files and subdirectories has been updated successfully with the following command:

` ls -l `

This should show the new group of all the files and subdirectories in the working directory.

Hence we can conclude that changing groupownership of the file or folder in Linux is a very easy task and doesn’t require a lot of effort. As long as you have root privileges, changing the group ownership of all the files and subdirectories can be done with very few commands in Linux.


数据运维技术 » Changing Groupownership of Files in Linux(chgrplinux)