The whoami command is used to display the user name with which you are currently logged in to the system. Sometimes, you may need to log in to a system and switch among different users, and you may not be sure with which user you are currently logged in. In such instances, you can use the whoami command to verify your current user name.
We can quickly view information about the current user by using the whoami command. The whoami command displays the owner of the current login session:
# whoami root
We can view the available options of the whoami command by passing the –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 GNU coreutils online help: [http://www.gnu.org/software/coreutils/] Full documentation at: [http://www.gnu.org/software/coreutils/whoami] or available locally via: info '(coreutils) whoami invocation'
If you encounter the below error while running the whoami command:
whoami: command not found
you may try installing the coreutils package as shown below as per your choice of distribution.
Distribution | Command |
---|---|
OS X | brew install coreutils |
Debian | apt-get install coreutils |
Ubuntu | apt-get install coreutils |
Alpine | apk add coreutils |
Arch Linux | pacman -S coreutils |
Kali Linux | apt-get install coreutils |
CentOS | yum install coreutils |
Fedora | dnf install coreutils |
Raspbian | apt-get install coreutils |
whoami Command Examples
1. Display currently logged username:
# whoami
2. Display the username after a change in the user ID:
$ sudo whoami
Conclusion
The whoami command prints the name of the current, effective user. This may differ from your login name (the output of logname) if you’ve used the sudo command.