3 Ways To Show Current Login Name In Linux and UNIX

By Leonard Cucos •  Updated: 05/30/21 •  3 min read

If you are looking for a way to show the current login name in Linux or UNIX systems, here are the three most used commands: whoami, id, and who. But there’s a fourth command not many know about!

If you decide to take a few moments to read the rest of this article, you will learn the difference between each command as well as additional information for each you might find useful in your troubleshooting process.

You will also know another way to show your current login name, a command that is much less used but provides additional useful information about the currently logged-in user in the system.

Let’s find out how to use each of the commands mentioned above.

1. whoami

The whoami command is an old UNIX command-line utility that shows the name of the current user logged in on a terminal. 

The command was developed by Richard Mlynarik as a convenient replacement for “who I am” and distributed first on BSD 2.9 as part of GNU Core Utilities (Coreutils). Later, the whoami command was widely adopted on Windows and all Linux/UNIX operating systems including macOS.

To identify the current user logged in, open a terminal and type the whoami command as shown in the example below:

Show Current Login Name in Linux and Unix: whoami. Source: nudesystems.com
Show Current Login Name: whoami

Take note that if you switch the user in the terminal, the command output will always show the last user logged in. 

For instance, if we use sudo -i to switch the current user to root, the whoami output will show root as the last logged in user as seen in the capture below:

Show Current Login Name in Linux and Unix: whoami [root]. Source: nudesystems.com
Show Current Login Name in Linux: whoami

2. id

The whoami command does not provide any additional details [UID, GID, Groups, etc.] besides the username of the last user logged in. A more useful command is the id command – though less popular. 

Show Current Login Name in Linux and Unix: id. Source: nudesystems.com
Show Current Login Name: id

3. who

An even less known command-line utility is who which comes with a suite of switches to print various information about the logged-in user and the system in use.

Show Current Login Name in Linux and Unix: who. Source: nudesystems.com
Show Current Login Name: who

4. echo $PATH

In rare cases, you may receive a “whoami: command not found” message on Linux/UNIX This is most likely caused because your $PATH environment variable does not contain the default path.

To fix this issue, type the following command in your terminal:

echo $PATH

The command output should be similar to the one shown in the capture below:

Show Current Login Name in Linux and Unix: echo $PATH. Source: nudesystems.com
Show Current Login Name: echo $PATH

If the echo $PATH command returns an empty field, run the command below to fix the issue:

export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

I hope you found this quick guide useful. If so, take a moment and share this article around.

Looking for more useful tutorials and tips and tricks for Linux? Check the Linux section of the website. There is a section for the UNIX fanboys as well – and is pretty awesome!

Leonard Cucos

Leonard Cucos is an engineer with over 20 years of IT/Telco experience managing large UNIX/Linux-based server infrastructures, IP and Optics core networks, Information Security [red/blue], Data Science, and FinTech.

medyum