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.
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:
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:
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.
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.
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:
The command output should be similar to the one shown in the capture below:
If the echo $PATH command returns an empty field, run the command below to fix the issue:
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!