whoami Command
Beginner User Management man(1)Print the current username
👁 9 views
📅 Updated: Mar 15, 2026
SYNTAX
whoami
What Does whoami Do?
whoami prints the effective username of the current user. It is the simplest way to check what user you are currently operating as, especially after su or sudo.
whoami is equivalent to id -un but more memorable. It is commonly used in scripts to verify the running user, check for root, and build user-specific paths.
whoami shows the effective user (after su/sudo), not necessarily the login user. Use who am i or logname to see the original login user.
whoami is equivalent to id -un but more memorable. It is commonly used in scripts to verify the running user, check for root, and build user-specific paths.
whoami shows the effective user (after su/sudo), not necessarily the login user. Use who am i or logname to see the original login user.
Options & Flags
| Option | Description | Example |
|---|---|---|
| (no options) | Print current effective username | whoami |
Practical Examples
#1 Check current user
Shows the effective username.
$ whoami
Output:
user
#2 After sudo
Shows that sudo runs commands as root.
$ sudo whoami
Output:
root
#3 In a script
Checks that a script is running as root.
$ if [ "$(whoami)" != "root" ]; then echo "Run as root!"; exit 1; fi#4 Build user path
Creates a user-specific configuration path.
$ CONFIG_DIR="/home/$(whoami)/.config/myapp"#5 Compare with logname
Shows both effective user and original login user.
$ echo "Effective: $(whoami), Login: $(logname)"
Output:
Effective: root, Login: admin
Tips & Best Practices
Script root check: Use [[ $(whoami) == "root" ]] or [[ $EUID -eq 0 ]] to check for root in scripts. $EUID is faster.
whoami vs who am i: whoami shows effective user. who am i shows the original login user (from utmp). They differ after su/sudo.
EUID is more reliable: In scripts, $EUID (effective UID) is more reliable and faster than calling whoami.
Frequently Asked Questions
How do I check what user I am?
Run whoami. It prints your effective username.
What is the difference between whoami and who am i?
whoami shows effective user (after su/sudo). who am i shows the original login user.
How do I check if I am root?
whoami shows root if you are root. In scripts: [[ $EUID -eq 0 ]] is the standard check.
Related Commands
More User Management Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →