How to use the command "groupmod" (with examples)

How to use the command "groupmod" (with examples)

This article provides examples of how to use the “groupmod” command, which is used to modify existing user groups in the system. The “groupmod” command allows you to change the group name and group ID for a given group.

Use case 1: Change the group name

Code:

sudo groupmod --new-name new_group group_name

Motivation: Sometimes you may want to change the name of an existing group to better reflect its purpose or to avoid confusion. The “groupmod” command allows you to easily change the group name without deleting and recreating the group.

Explanation: The “–new-name” option followed by the new group name specifies the new name you want to assign to the group. The “group_name” argument represents the current name of the group that you want to modify.

Example output:

$ sudo groupmod --new-name marketing sales

This command changes the group named “marketing” to “sales”. The output will not display any information unless an error occurs.

Use case 2: Change the group ID

Code:

sudo groupmod --gid new_id group_name

Motivation: In some cases, you may need to change the group ID (GID) of a group to ensure consistency with other resources or to avoid conflicts with existing IDs. The “groupmod” command allows you to modify the GID of a group without affecting its name or other properties.

Explanation: The “–gid” option followed by the new group ID specifies the new GID you want to assign to the group. The “group_name” argument represents the name of the group whose ID you want to modify.

Example output:

$ sudo groupmod --gid 1001 sales

This command changes the GID of the group “sales” to 1001. The output will not display any information unless an error occurs.

Conclusion:

The “groupmod” command is a powerful tool for modifying existing user groups in the system. With the examples provided in this article, you should be able to change the group name and group ID of a group easily. Remember to use the appropriate options and arguments as per your requirements to ensure accurate modification of the group.

Related Posts

Ansible Playbook Command (with examples)

Ansible Playbook Command (with examples)

Ansible is an open-source automation tool that simplifies IT infrastructure management by automating tasks such as server configurations, software installations, and application deployments.

Read More
How to use the command dot_clean (with examples)

How to use the command dot_clean (with examples)

This article will provide several use cases for the dot_clean command, which is used to merge .

Read More
How to use the command 'act' (with examples)

How to use the command 'act' (with examples)

The ‘act’ command is a tool that allows you to execute GitHub Actions locally using Docker.

Read More