Linux Commands to Display Current Login Name
By default, Linux distribution has the username prompt in the terminal but if the user has changed their name, then try the below commands to find the current login name. All we need is to open the terminal and display the current login name via the following commands:
- who Command
- whoami Command
- $USER Command
- w Command
- logname Command
- lslogins Command
- last Command
- id Command
1: who Command
The who command will display the current login name with the date and time. It reads the information from the default file location.
You can also -a flag with the Who command to get the detail of the current logged in user:
2: whoami Command
Unlike Who the whoami will display a straight answer only the username, so if you only want to check the username then execute:
3: $USER Command
Another way to only get the login name as in the whoami command, execute the $USER command:
4: w Command
The w command provides the more information about the current active user on your system:
Here TTY is the type of the terminal they are logged in, FROM is the remote host, LOGIN@ is the time of user login, JCPU is the joint CPU time used by all processes, PCPU is the CPU time of the current process and WHAT is the current process
5: id Command
The id command displays the information of user and groups associated with specific user:
6: logname Command
The logname command prints the one word, only the name of currently active user:
7: last Command
This command prints the list of users, last logged in on your system:
8: lslogins Command
It displays the list of login users with their last login time and their names, here -u flag displays only the user’s information:
Bottom Line
As in Linux, different users can log in to the same system, and in that case one can monitor their activities. You can find the current login name via different commands in the terminal. In this tutorial, we have learned to find the username with who, whoami, what, w, and lslogins commands.
Try every command and check which works best for you.