Get Current Username in Linux

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

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.

root@tutorialkart#

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

root@tutorialkart# whoami
root
ADVERTISEMENT

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.

prasanna@tutorialkart:/tutorialkart$

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

prasanna@tutorialkart:/tutorialkart$ whoami
prasanna

Conclusion

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