username Command in Linux With Examples
Last Updated :
20 Mar, 2025
Linux as an operating system holds the capabilities of handling multiple users each with a username and a display name (Full Name). So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added its information is stored in the “/etc/passwd” file. It keeps the username and other related details. Here are some commands to fetch username and its configurations from the Linux host.
There is no specific “username” command in Linux but there are other several sets of commands that let the user access the various users on the machine.
How to Check Username and Display Name in Linux
1. Using `whoami` Command to Check User Name in Linux
Type whoami
in your terminal. This simple command instantly displays the username of the effective user currently running the shell.
whoami

whoami command to check username
2. Using `id` Command to Check User Name in Linux
id: This command basically prints the information of real and effective user or in other words the current user.
Syntax:
id
Example:

Use the id command followed by the username to print specific user information.
Syntax:
id username
Example:

3. Using getent
Command to Check Username and Display Name in Linux
getent : This command fetches user information from database configured in /etc/nsswitch.conf. file which also includes passwd database.
Syntax:
getent passwd
Example:
Each line above has seven fields separated by colons which contains the following information-
- Username
- Encrypted Password
- User ID number(UID)
- User group ID number(GID)
- Full name of the user(GECOS)
- user home directory and
- Login shell respectively.
4. Using finger
Command to Retrieve Username and Display Name
finger: It displays the current user’s real name along with the terminal name, write status, idle time, and login time.
Syntax:
finger
Example:

Use the finger command followed by the username to print specific user information.
Syntax:
finger username
Example:

5. Using lslogins
Command to View Username and Display Name
It displays information about known users in the system. By default, it will list information about all the users in the system.
Syntax:
lslogins -u
Example:

6. Using `cat` Command to Check User Name in Linux
cat : This command fetches and prints user information from /etc/passwd/ file, where each line contains seven fields as in the output of getent and less command.
Syntax:
cat /etc/passwd/
Example:

user account information
7. Using `compgen` Command to Check User Name in Linux
This command also displays the name of all the users without any additional information. For more details refer the article compgen command in Linux
Syntax:
compgen -u
Example:

Note: One can use compgen -c command to list all commands available if he/she is not the admin on a Linux system and doesn’t have the sudo access.
8. Using `$USER` Command to Check User Name in Linux
The $USER
environment variable holds your username’s value. Run echo
$USER
to retrieve it.
echo $USER

Check User Name
Conclusion
In this article, we explored multiple ways to check usernames and display names in Linux. While whoami
, id
, and compgen
help identify usernames, commands like getent
, finger
, and lslogins
provide both the username and the display name (Full Name in the GECOS field). These commands are essential for system administration, helping manage users efficiently. If you need to modify a user’s display name, use the chfn
command.
Similar Reads
tty Command in Linux with Examples
In the Linux operating system, everything is represented within a file system, including hardware devices and terminal interfaces. Among these, the terminal is also treated as a file, allowing users to interact with the system by sending inputs and receiving outputs. One essential command related to
3 min read
type command in Linux with Examples
The type command in Linux is a useful utility for identifying how the shell will interpret a given command. It provides information on whether a command is a shell built-in, external binary, function, or alias, helping users understand the source of the command and its behavior. The command is parti
3 min read
uname command in Linux with Examples
Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
4 min read
unexpand command in Linux with Examples
To convert the leading spaces and tabs into tabs, there exists a command line utility called unexpand command. The unexpand command by default converts each space into tabs writing the produced output to the standard output. Syntax $unexpand [OPTION]... [FILE]...where, OPTION: Represents the various
3 min read
uniq Command in Linux with Examples
The uniq command in Linux is a command-line utility that reports or filters out the repeated lines in a file. In simple words, uniq is the tool that helps to detect the adjacent duplicate lines and also deletes the duplicate lines. uniq filters out the adjacent matching lines from the input file(tha
7 min read
until command in Linux with Examples
until command in Linux is used to execute a set of commands as long as the final command in the 'until' Commands has an exit status that is not zero. It is mostly used where the user needs to execute a set of commands until a condition is true. Syntaxuntil COMMANDS; do COMMANDS; donewhere, CONDITION
2 min read
Linux | Uptime command with examples
It is used to find out how long the system is active (running). This command returns set of values that involve, the current time, and the amount of time system is in running state, number of users currently logged into, and the load time for the past 1, 5 and 15 minutes respectively. Linux uptime S
5 min read
How to add User in Linux | useradd Command
useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the
5 min read
usermod command in Linux with Examples
usermod command or modify user is a command in Linux that is used to change the properties of a user in Linux through the command line. After creating a user we have to sometimes change their attributes like password or login directory etc. so in order to do that we use the Usermod command. The info
4 min read
username Command in Linux With Examples
Linux as an operating system holds the capabilities of handling multiple users each with a username and a display name (Full Name). So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added it
4 min read