Change Group ID of a file or directory in Ubuntu

Published: October 09, 2022

Change Group ID of a file or directory in Ubuntu

This article is in continuation to previous article - Change Group ID in Ubuntu. Just to brief you, if we change a Group's ID then, such changes do not reflect in files or directories created earlier. We need to manually change Group ID of all those files which were part of that specific group whose Group ID was modified.

What happens is, once we change a Group's ID. The files and directories, which the group owns, are now no longer part of that group. Although, we have already changed the group ID and it should automatically reflect modifications to respective files and directories. But, that doesn't just happen. We need to manually change group ID of all those existing files/directories which are part of the group.

If we don't do that (i.e. change group ID of file/directories) then the group would would lose access to those files/directories. In short, we need bring those files/directories under the fold of group again.

It is worth mentioning here that, if Group ID of files/directories isn't modified then the system would automatically shift privileges of those to 'others' category (i.e. those who is neither an owner nor part of the group).

Note: Following operations require you to have superuser privileges. In case you don't have one then, we advise you to contact your System Administrator for assistance.

Change Group ID of a file or directory

Use the following command to check for Group ID of a file/directory -

ls -n

For instance, we changed the group ID from 1777 to 1001 of a group - test and still the changes weren't reflected in file - test_file.

-rw-rw---- 1 1001 1777 0 Oct 9 08:29 test_file

So, we had to do it manually using chgrp command-line utility -

chgrp <group_ID> <file_name>

For instance,

chgrp 1001 test_file

ls -n command returned with the following -

-rw-rw---- 1 1001 1001 0 Oct 9 08:32 test_file

chgrp command-line utility is used to change the group of files or directories.

In conclusion, we have covered how to change Group ID of a file or directory in Ubuntu.