whoami command
whoami
- print effective userid
The whoami
command in Linux is an utility that displays the username of the current user running the command. It’s a quick way to confirm your identity in the terminal, especially useful in multi-user systems or when switching users with su
or sudo
.
Usage: whoami [OPTION]...
OPTION
: Rarely used, but there’s one flag available (--help
or--version
).
Examples
-
Basic usage
Running
whoami
prints the effective username of the current session.$ whoami
- Output:
alice
(if your username is "alice"). - Shows the user you’re logged in as or the effective user after privilege changes.
- Output:
-
Context with
sudo
orsu
whoami
reflects the effective user, not necessarily the login user, making it handy when switching identities.$ sudo whoami
- Output:
root
(becausesudo
elevates you to the root user).
$ su -
whoami- After entering the root password, output:
root
.
- Output:
To get help related to the whoami
command use --help
option
$ whoami --help
Usage: whoami [OPTION]...
Print the user name associated with the current effective user ID.
Same as id -un.
--help display this help and exit
--version output version information and exit