/**/ Difference between id and lid commands - Dextutor

Difference between id and lid commands

Both the commands are useful to display the information related to users and groups. Therefore let’s understand the difference between using the id and lid commands in Linux.

id command

Use

prints the user and group ids. The commands prints the user id and group ids of the user whose name is passed as the argument to the id command.

Syntax

$id [OPTION]… [USER]

Example

Difference between id and lid commands

The example shows how id command shows the details about the user Linux. The output shows:
UID of user: 1002
GID of the primary group to which the user belongs: 1007
The GIDs of all Groups: 1007 and 1005 (which is the Supplementary Group)

Options with id command

-g: prints only the effective group ID (or the primary group ID)

-G: prints the ID of all the groups of which the user is a member.

-u: prints only the UID of the user

lid command

Use

the lid command lists the groups to which a user belong. Alternatively, It can also display the users that belong to a particular group.

Syntax

lid [OPTION]… [name]

If the name is of a user, the groups to which the user belongs are listed.
If the name is of a group, the users belonging to that group are listed.

Example

Difference between id and lid commands

The above example lists the groups of the user Linux. So, the user Linux is a member of two groups: Apple, having GID 1005 and Linux, having GID 1007.

Now, lets check the list of users who belong to group Apple.

Difference between id and lid commands

Two users, Linux (UID=1002) and STUDENT (UID=1003) are members of the group Apple.

Remeber to use the -g option when specifying a group with lid command.

Questions related to id and lid command

Q1. Create two users U1 and U2. Create a group G1. Add U1 and U2 to the group G1. Verify that the given tasks have been achieved.

Q2. List all the groups to which the root users belongs to.

Relevant Commands

useradd
usermod
groupadd
groupmod
userdel
groupdel