whoami(1)
Print the username of the current user.
UbuntuDebianFedoraArch
Synopsis
whoamiDescription
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
whoamiShow that you are root when running a command with sudo
sudo whoamiUse whoami in a conditional to check if the script is running as root
if [ "$(whoami)" = "root" ]; then echo "Running as root"; fiLog the current username to a file using command substitution
echo "User: $(whoami)" >> logfile.txt