id command in Linux with examples
Last Updated :
05 Sep, 2024
The 'id' command in Linux is a powerful tool used to display user and group names along with their numeric IDs (User ID - UID or Group ID - GID) of the current user or any specified user on the system. This command is particularly useful for system administrators and users who need to verify user identities and associated permissions.
What does the 'id' Command Do?
This command is useful to find out the following information as listed below:
- User name and real user id.
- Find out the specific User UID.
- Show the UID and all groups associated with a user.
- List out all the groups a user belongs to.
- Display the security context of the current user.
Syntax:
id [OPTION]… [USER]
Options:
- '-g': Prints only the effective group ID of the user.
- '-G': Prints all group IDs associated with the user.
- '-n': Displays names instead of numeric IDs.
- '-r': Shows the real ID instead of the effective one.
- '-u': Prints only the effective user ID.
- '--help': Displays help messages for the id command and exits.
- '-version': Shows the version information and exits.
Note: Without any OPTION it prints every set of identified information i.e. numeric IDs.
'id' command Examples in Linux
Let us look at some of the examples of 'id' command in Linux to better understand the concept.
1. To print your own 'id' without any Options
To display your own user and group IDs, simply run:
id

The output shows the ID of current user UID and GID.
2. To find a specific users 'id'
Now assume that we have a user named master, to find his UID we will use the command:
id -u master

This will display only the UID of the specified user.
3. To find a specific users GID
Again assuming to find GID of master, we will use the command:
id -g master

This option will show the effective group ID of the user.
4. To find out UID and all groups associated with a username
In this case we will use the user "master" to find UID and all groups associated with it, use command:
id master

5. To find out all the groups a user belongs to
Displaying the UID and all groups a user "master" belongs to:
id -G master

6. To display a name instead of numbers
By default the 'id' command shows us the UDI and GID in numbers which a user may not understand, with use of '-n' option with '-u', '-g' and '-G'. Use command(s):
id -ng master
or
id -nu master
or
id -nG master

7. To display real id instead of effective id
To show the real id with the use of '-r' option with '-g', '-u' and '-G, use command(s):
id -r -g master
id -r -u master
id -r -G master

Conclusion
By mastering the 'id' command and understanding its various options, you can enhance your ability to manage and troubleshoot user permissions on Linux systems. This command is a key tool in your Linux toolkit if you’re a system administrator or even a casual user.
Similar Reads
Head Command in Linux With Examples Need to quickly view the beginning of a file in Linux? The head command is your best option. This essential command-line tool enables users, developers, and system administrators to preview the start of log files, configuration files, CSV datasets, and other text documents in seconds.The head comman
6 min read
help Command in Linux with examples If youâre new to the Linux operating system and struggling with command-line utilities, the help command is one of the first tools you should learn. As its name suggests, the 'help' command provides detailed information about built-in shell commands, making it an essential resource for beginners and
5 min read
hexdump command in Linux with examples The 'hexdump' command in Linux is a versatile utility used to display file content or data from standard input in a human-readable format. It is invaluable for programmers and system administrators for debugging binary data, analyzing file structures, and verifying data integrity. Here we will get a
5 min read
How to Display Command History in Linux | history Command The history command in Linux is essential for terminal users, enabling them to view, search, and manipulate previously executed commands. Now, mastering this Linux command allows for efficient commands of commands, automation of repetitive tasks, and troubleshooting without the need to retype length
3 min read
host command in Linux with examples host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more s
2 min read
hostid command in Linux with examples hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhost
1 min read
hostname command in Linux with examples hostname command in Linux is used to obtain the DNS (Domain Name System) name and set the system's hostname or NIS (Network Information System) domain name. A hostname is a name given to a computer and attached to the network. Its main purpose is to uniquely identify over a network. Syntax of the `h
5 min read
hostnamectl command in Linux with Examples hostnamectl command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system. Syntax: hostnamectl [OPTIONS...] COMMAND .... Where COMMAND c
2 min read
htop command in Linux with examples htop command in Linux system is a command line utility that allows the user to interactively monitor the systemâs vital resources or serverâs processes in real-time. htop is a newer program compared to top command, and it offers many improvements over top command. htop supports mouse operation, uses
4 min read
hwclock command in Linux with examples hwclock also called Real Time Clock (RTC), is a utility for accessing the hardware clock. The hardware clock is independent of the OS(operating system) you use and works even when the machine is shut down. The hardware clock is also called a BIOS clock. A user can also change the date and time of th
3 min read