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"

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!