How to find current logged-in user in Linux Terminal


If you what to know the currently logged-in user, you can make use of the command whoami on the Linux Terminal.

Example:
# whoami

c2c

Now let's switch the user and check the same command,

# su mike

# whomai

mike

If you are writing bash scripts and want to get the currently logged-in user, you can make use of the $USER environment variable.


Example:
#!/bin/bash
echo "The Current User: $USER"
Know the current Logged In user Linux

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap