Linux-for-Sys-Ads/C2/Modifying-and-Deleting-Groups/English-timed
From Script | Spoken-Tutorial
Time | Narration |
00:01 | Hello and welcome to the spoken tutorial on Modifying and Deleting Groups in Linux. |
00:09 | In this tutorial we will learn about
groupmod command and groupdel command |
00:17 | We will do this through some examples. |
00:21 | To record this tutorial, I am using Ubuntu Linux 16.04 OS |
00:28 | To practice this tutorial, you should have gone through the Linux System Administration tutorials on this website and |
00:36 | you must have root access to your computer. |
00:41 | Open the Terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard. |
00:49 | First, you should login as superuser or root user. |
00:56 | Here onwards, please remember to press the Enter key after typing each command. |
01:03 | In the series, we had created the group electronics. |
01:07 | Let us check the details of the group from the /etc/group file. |
01:14 | Notice that group electronics has GID 1006. |
01:20 | Also, the list of members field is empty. |
01:25 | So, no user has group electronics as a supplementary group. |
01:31 | Let’s check the /etc/passwd file to know how many users belong to the primary group electronics. |
01:42 | Notice that, the users testmod and amit have 1006 in the fourth field. |
01:50 | It means the users testmod and amit belong to the group electronics |
01:57 | Let me create a document testfile.txt in the user account testmod |
02:04 | So, login as user testmod |
02:08 | Now if we create any document, then that document will be owned by the group electronics.Let's do that. |
02:17 | First we’ll create a text file named testfile.txt |
02:24 | I am going to use vi text editor to do so. |
02:28 | But you can use any other text editor of your choice. |
02:33 | At the command prompt type vi space testfile.txt |
02:41 | Press I on the keyboard to insert text. |
02:45 | Now type this text, “Hi I am user testmod” |
02:50 | Press the Escape key on the keyboard to exit from the insert mode. |
02:55 | Then press colon w q |
02:59 | w is used to save the typed text in the text file. |
03:04 | And q is used to quit the editor.
Now press Enter. |
03:11 | We are back to the command prompt. |
03:14 | Now type, ls space hyphen l space testfile.txt |
03:22 | Notice the third and fourth fields. |
03:25 | The document belongs to user testmod and group electronics. |
03:31 | Now let us start modifying the group with the groupmod command. |
03:37 | The groupmod command is used to modify the definition of the group specified in the command. |
03:45 | This is the syntax. |
03:49 | Here the options field is not mandatory. |
03:54 | groupmod command can be used to modify- the group name,
GID |
04:00 | GID to a non-unique number |
04:04 | Suppose, we want to modify our group’s name from electronics to electrical. |
04:10 | To do so, let me switch back to the root login. |
04:15 | Exit from the user testmod. |
04:19 | Now type groupmod space hyphen n space electrical space electronics |
04:28 | Then type cat space /etc/group |
04:34 | Notice that the group with GID 1006 is now named as electrical. |
04:42 | You can also change the GID of a group to a new unique non-negative number. |
04:50 | Suppose, you are planning to use number 1100 as the new GID value. |
04:57 | So, first ensure, that the number 1100 is not present as GID in any other group. |
05:06 | From the output of /etc/group 1100 is not set as a GID value to any of the group. |
05:16 | This type of manual checking is not a good idea, if you have a large number of groups. |
05:22 | Instead we can use the grep command to check if the number is present or not. |
05:30 | As an assignment, try this out on your own. |
05:35 | Now to change GID value, type groupmod space hyphen g space 1100 space electrical |
05:48 | Now check the details of the file /etc/group |
05:54 | Notice that GID of electrical is now 1100. |
06:00 | We know that user testmod belongs to the group electrical. |
06:05 | Let’s check /etc/passwd file for the entry of the user testmod. |
06:14 | Notice that the GID value in the fourth field is also updated. |
06:19 | It is showing the current value 1100. |
06:24 | The group ID has changed. |
06:27 | But the files belonging to this group will retain the old group ID value. |
06:34 | So we must change their group ID manually. |
06:39 | To find all files belonging to the group with GID 1100, type find space slash home space hyphen gid space 1100 |
06:55 | This may take some time. |
06:58 | We have not got any output. |
07:01 | Recall the previous command. |
07:04 | Change the group ID value to 1006 that is the previous group ID of electrical. |
07:12 | Notice, the file testfile.txt still belongs to group ID 1006. |
07:20 | Please note the complete path of the file testfile.txt |
07:26 | To change the group ID for the file testfile.txt to 1100, type
chgrp space 1100 space , then type the full path of file testfile.txt. |
07:44 | chgrp command is used to change the group of the file. |
07:49 | The command has executed without any error. |
07:53 | Recall the command to display all the files belonging to group ID 1100. |
08:00 | Notice the output shows testfile.txt file. |
08:05 | Please note, you may have multiple files belonging to old group ID value. |
08:12 | Changing group ID manually one by one will be a tedious job in that case. |
08:18 | Try writing shell script for this. |
08:22 | Now we know how to change the GID of a group to another unique value.
Let’s move on. |
08:30 | Recall the command to display /etc/group. |
08:36 | Notice, literature club has GID 1007. |
08:42 | Let us try to assign this 1007 as the new GID of electrical. |
08:49 | Notice, it is showing an error, GID 1007 already exists. |
08:56 | So, we cannot change the group ID to a non-unique value with only hyphen g option. |
09:04 | To change the group ID to a non-unique value, you will need hyphen o option along with hyphen g option |
09:14 | Let me try to set the GID to 1007 now. |
09:19 | Recall the previous command. |
09:22 | Now, after 1007, give space and then type hyphen o |
09:30 | The command has executed successfully. |
09:34 | Next, execute the cat /etc/group command |
09:41 | Notice that both electrical and literature_club now have same GID 1007. |
09:50 | So, we have learnt about groupmod command. |
09:54 | Now let’s learn about groupdel command. |
09:58 | groupdel command is used by the root or the superuser to remove a group. |
10:05 | Syntax is groupdel space groupname |
10:10 | Let me remove the group named electrical. |
10:14 | Type groupdel space electrical |
10:19 | Notice that Linux has thrown some error. |
10:23 | It is telling that cannot remove primary group of the user amit |
10:29 | So, you cannot delete electrical because it is the primary group of an existing user amit. |
10:37 | You must first delete the user amit and then you can remove electrical.
Let’s try this. |
10:46 | For deleting user amit, type userdel space hyphen r space amit |
10:54 | The command may report that the user's mail spool was not found.
This warning can be ignored. |
11:03 | Now execute the groupdel command. |
11:07 | Once again we got the error.
Says, cannot remove the primary group of the user testmod |
11:15 | Let me delete the user testmod. |
11:19 | Once again we got the user's mail spool error. |
11:24 | Now execute the groupdel command for the group electrical. |
11:29 | This time we did not get any error. |
11:33 | Now execute the cat /etc/group command |
11:40 | We can see that there is no entry for electrical. |
11:44 | The group named electrical is deleted now. |
11:48 | The important point you have to keep in mind is:
You are not permitted to remove the primary group of any existing user. |
11:58 | You must remove the user first. Then you can remove that user's primary group. |
12:05 | Now what about the files owned by the deleted group? |
12:09 | groupdel will not automatically check for files owned by the deleted group. |
12:15 | You should manually search all file systems for such files. |
12:21 | You can use the find command for this search. |
12:25 | You should ensure that no files remain owned by this deleted group. |
12:31 | You can either delete those files or change the group ownership using chgrp command.
I leave it as an exercise for you. |
12:43 | Switch to the terminal. |
12:45 | Exit from the root user access. |
12:49 | This brings us to the end of this tutorial.
Let us summarize. |
12:55 | In this tutorial we learnt about-
groupmod command to modify the group name |
13:02 | GID
GID to a non-unique number |
13:08 | groupdel command to delete a group |
13:11 | As an assignment: Create two new groups
civil with GID 1201, mechanical with GID 1202 |
13:24 | Add a user suman with primary group civil |
13:29 | Let suman create a document test.txt and type any text of your choice. |
13:36 | Modify the GID of the group civil to 1203 |
13:42 | Change the group ownership of the file test.txt. |
13:47 | Delete group civil |
13:49 | Delete file test.txt |
13:53 | The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
14:01 | The Spoken Tutorial Project team conducts workshops using spoken tutorials and gives certificates.
For more details, please write to us. |
14:13 | Pls post your timed queries in this Forum. |
14:17 | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. |
14:23 | The script has been contributed by Antara. And this is Praveen from IIT Bombay signing off.
Thanks for joining. |