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 is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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