Linux Commands

Linux Command to Display Current Login Name

Knowing the current login name is important for determining the identity of the user who is currently logged into the system especially if multiple people are using a single Linux system. For that there are various commands through which you can find the currently active user in the Linux mint. We will discuss them in this article.

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:

  1. who Command
  2. whoami Command
  3. $USER Command
  4. w Command
  5. logname Command
  6. lslogins Command
  7. last Command
  8. 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.

$ who

You can also -a flag with the Who command to get the detail of the current logged in user:

$ who -a

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:

$ whoami

3: $USER Command

Another way to only get the login name as in the whoami command, execute the $USER command:

$ echo $USER

4: w Command

The w command provides the more information about the current active user on your system:

$ w

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:

$ id

6: logname Command

The logname command prints the one word, only the name of currently active user:

$ logname

7: last Command

This command prints the list of users, last logged in on your system:

$ last -p now

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:

$ lslogins -u

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.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.