Skip to main content

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.
  • Context with sudo or su

    whoami reflects the effective user, not necessarily the login user, making it handy when switching identities.

    $ sudo whoami
    • Output: root (because sudo elevates you to the root user).
    $ su -
    whoami
    • After entering the root password, output: root.
$ 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