This tutorial explains Linux “id” command, options and its usage with examples.
Description :
This command is useful to find out the following information:
1. Find a specific user’s UID.
2. Find a specific user’s UID.
3. Find out all the groups a user belongs to.
4. Find the UID and all groups associated with a user.
5. Display security context of the current user.
Usage :
id [OPTION]… [USERNAME]
Options :
-a
ignore, for compatibility with other versions
-g, –group
print only the effective group ID
-G, –groups
print all group IDs
-n, –name
print a name instead of a number, for -ugG
-r, –real
print the real ID instead of the effective ID, with -ugG
-u, –user
print only the effective user ID
–help
display this help and exit
Examples :
1. To display all system identifications for the current user, enter:
$ id uid=1544(abc) gid=300(abc) groups=0(system),10(audit)
2. Find a specific user’s UID
In this example, find abc’s UID, type:
$ id -u vivek 1544
3. Find a specific user’s GID
In this example, find a abc’s GID, run:
$ id -g vivek 300
4. How do I see the UID and all groups associated with a user name?
In this example, find the UID and all groups associated with a user called ‘root’, enter:
$ id root uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),398(com.apple.access_screensharing),399(com.apple.access_ssh)
5. Find out all the groups a user belongs to…
In this example, display the UID and all groups associated (secondary groups) with a user called ‘abc’, run:
$ id -G abc 20 12 61 79 80 81 98 33 100 204 398 399
6. Display a name instead of a UID/GID
By default, id command displays number for the -G, -g and -u options. You can force id command to display the name of the UID or GID instead of the number for the -G, -g and -u options by passing the -n option as follows:
$ id -nG abc staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin _appstore _lpoperator _developer com.apple.access_screensharing com.apple.access_ssh
7. How do I display real ID instead of the effective ID for specified user?
You can show the real ID for the -g, -G and -u options instead of the effective ID by passing the -r option:
$ id -r -u abc 501
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books
- Check Linux Books