In this tutorial, you will learn how to use the
whoami command with examples. The
whoami command allows Linux users to see the currently logged-in user. The output displays the username of the effective user in the current shell. Additionally,
whoami is useful in bash scripting to show who is running the script.
- A system running Linux.
- Access to the command line/terminal.
whoami Command Syntax
The syntax for the whoami command is:
$ whoami [option]
whoami Command Options
The whoami command comes with the two following options:
|–help||Shows a help message and exits.|
|–version||Shows the version information and exits.|
whoami Command Examples
There are several different ways to use whoami. The examples below explain common use cases of the whoami command.
Basic whoami Usage
When running whoami without any options, the output shows the name of the currently logged-in user.
To test the command, open the terminal and enter:
The output prints the name of the effective user.
Verify the Effective User
When you have more than one account, use whoami to verify the username after switching to a different account.
For example, switch to another user with the su command:
$ su [account name]
Then, run the whoami command to verify the effective user:
Since you executed the command as a different user, the terminal shows another username.
Check an Account for Sudo Permissions
Use the whoami command to check if a user has sudo privileges. To do this, execute the command with sudo and provide the password:
$ sudo whoami
Check whoami Version
To check the version of the whoami command, execute:
$ whoami --version
After following this tutorial, you should know how to use the
whoami command to find the name of the effective user on a Linux system. You can use it as you want. Enjoy!!!
Related Linux Tutorials: