Groupmod Command in Linux - TechvBlogs

Groupmod Command in Linux

Explore the versatility of the groupmod command in Linux through our comprehensive guide. Learn how to manage user groups efficiently, enhancing your system administration skills effortlessly.

Smit Pipaliya - Author - TechvBlogs
Smit Pipaliya

6 months ago

TechvBlogs - Google News

For Linux users, proficiency in group management is crucial. Interacting with groups is a constant aspect of your Linux journey, necessitating skills in effective group management. Key tasks include changing a group's name or modifying its ID. This guide empowers you with the knowledge to navigate group management seamlessly. Mastering actions like altering group names and IDs is essential for efficient Linux system administration.

Simplifying group management, the groupmod command in Linux provides diverse options for swift group administration. This guide delves into the intricacies of the groupmod command, offering a comprehensive overview and multiple examples on its effective utilization. Dive into the details and enhance your understanding of managing groups effortlessly on Linux. Keep reading to unlock the potential of the "groupmod" command in your Linux system administration journey.

How to Use the Groupmod Command in Linux

Envision a situation where you need to alter the group name of your files or change the group ID to assign it a specific identifier. Such tasks are achievable with the "groupmod" command, featuring two key options that we'll explore in this article. Mastering these options empowers you to efficiently handle group-related modifications, enhancing your control and flexibility over file and user group management.

The -g or --gid GID option facilitates the alteration of the group ID of the specified group, assigning it the specified GID.

On the other hand, the -n or --new-name NAME option allows you to provide a new NAME for your group, effectively replacing the existing group name.

To access the help page and explore additional options, you can execute the command groupmod --help. However, the primary options covered previously are the main ones used. Now, let's delve into various examples to better understand how to use the groupmod command.

Example 1: Change the Group Name

In Linux, groups play a crucial role in organizing files. You can view all the groups on your Linux system by accessing the /etc/group file. Using commands like cat to open it, you can see a comprehensive list of available groups along with their corresponding group IDs. Here's an example of how such a list appears:

cat /etc/group

Now, let's examine the group to which a directory named new in our current directory belongs. To do this, we can use the ls command as demonstrated below:

ls -ld new

Make sure to replace the directory name with the one that matches your case. Alternatively, you can use the long listing option with ls to get details about all files and directories, including their groups.

Before proceeding to change the group's name, it's essential to confirm the current group ID. Check the group ID by examining the groups list and locating the target group using the grep command, as illustrated below:

Here, our target group has an ID of 1000.

To change the group's name, execute the groupmod command as follows:

sudo groupmod -n ubuntu12 techvblogs

In the previous command, the -n option is used to change the group name. Replace ubuntu12 with your new group name and techvblogs with the current group name as per your requirement.

After executing the command, enter your password to authenticate it. Next, rerun the earlier command to check under which group the new directory belongs. You should see that the group name has been successfully changed.

ls -ld new

To further verify, rerun the earlier command to check the group ID. You will notice that the new group name matches the earlier group ID, confirming that the group name has been successfully changed.

cat /etc/group | grep ubuntu12

Example 2: Change the Group ID

cat /etc/group | grep ubuntu12

For our case, the current group ID is 1000. To modify it and assign a new group ID, which, in this example, is 2300, execute the command as follows:

sudo groupmod -g 2300 -o ubuntu12

Remember to replace 2300 with your desired group ID and ubuntu12 with your target group.

Verify that the change of group ID worked successfully.

cat /etc/group | grep ubutnu12

Example 3: Change the Group Name and ID Simultaneously

Simultaneously changing the group name and ID with one command is possible. To do that, you need to specify the new group name and ID with the following syntax:

sudo groupmod --new-name newname --gid 3243 ubuntu12

Once you run the command, list the groups to check the current name and the ID. In our example, we can confirm that we successfully changed the group name and ID.

cat /etc/group | grep newn*


The groupmod command is a useful tool for managing groups in Linux, allowing you to easily change a group's name and ID. In this guide, we provided a detailed explanation of the command and offered examples to demonstrate its usage.

Comments (0)


Note: All Input Fields are required.