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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!