Get Current Username in Linux

To get current username in Linux, we can use whoami command.

</>
Copy
whoami

Example 1 – Username of root user

In this example, we will get the user name of the root user.

We are currently logged in as root.

</>
Copy
root@tutorialkart#

To get the user name of the root user, execute the whoami command.

</>
Copy
root@tutorialkart# whoami
root

Example 2 – Username of another user

In this example, we will get the user name of another user.

Now we have logged in as another user, say prasanna.

</>
Copy
prasanna@tutorialkart:/tutorialkart$

Let us get the user name of this user using whoami command.

</>
Copy
prasanna@tutorialkart:/tutorialkart$ whoami
prasanna

Conclusion

In this Linux Tutorial, we learned how to get the user name of current user using whoami command.