Ways to know the Logged in Username using Terminal [macOS/Linux/Unix]

In order to know the current user (username) who is logged in your an try one of the below commands on the Terminal.

1. Using whoami command:

# whoami
# man whoami

     whoami – display effective user id


     The whoami utility has been obsoleted by the id(1) utility, and is
     equivalent to “id -un”.  The command “id -p” is suggested for normal
     interactive use.

     The whoami utility displays your effective user ID as a name.

2. Using id command:

id is a command that you can use to return user identity.

id -un
-u      Display the effective user ID as a number.

-n      Display the name of the user or group ID for the -G, -g and -u
        options instead of the number.  If any of the ID numbers cannot
        be mapped into names, the number will be displayed as usual.

3. Using $USER Environment Variable:

# echo $USER
Know logged-in username command

These commands work on all flavors of Unix and Unix-like operating systems including Linux and macOS

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