LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

whoami

Print current effective username

TLDR

Print the current username
$ whoami
copy

SYNOPSIS

whoami [--help] [--version]

DESCRIPTION

whoami prints the username associated with the current effective user ID. It's equivalent to id -un.This is useful in scripts to determine which user is running the script, especially when the script might be run via sudo or after using su to switch users.Unlike who am i which shows the login name from utmp, whoami shows the effective user ID name, which may differ after sudo or su.

PARAMETERS

--help

Display help and exit
--version
Display version and exit

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

After sudo, whoami shows the target user (usually root), not the original user. Use logname or who am i to get the original login name.The command shows the effective user ID. In setuid programs, this may differ from the real user ID.

SEE ALSO

who(1), id(1), logname(1), users(1)

Copied to clipboard
Kai