$linuxjunkies
>

whoami(1)

Print the username of the current user.

UbuntuDebianFedoraArch

Synopsis

whoami

Description

The whoami command prints the login name of the current effective user. It is equivalent to id -un and reads the UID from the environment or system calls, then translates it to a username.

This is useful in scripts, shell prompts, and for quickly confirming your identity when logged in, especially over remote sessions or after using su or sudo.

Examples

Display the current logged-in user's username

whoami

Show that you are root when running a command with sudo

sudo whoami

Use whoami in a conditional to check if the script is running as root

if [ "$(whoami)" = "root" ]; then echo "Running as root"; fi

Log the current username to a file using command substitution

echo "User: $(whoami)" >> logfile.txt

Related commands