The quick answer for which Linux command can be utilized to display your current login name the answer is: whoami
Alternative commands [Linux/UNIX]:
The whoami command is an old UNIX command-line utility that displays 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.
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 with 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 guide useful. You can find more interesting Linux/UNIX stuff here.