Generally, on your command prompt you will find a username is printed on the command prompt. But in some shells such as csh, by default you will not see your username there. So this command particularly is used with the shell which doesn’t print the username on their shell.
whoami Command in Linux
The whoami command print the effective username of the user who runs the whoami command.
The syntax for whoami command in Linux:
whoami [OPTION]
To run this command, just type whoami
in the command prompt. For this example, here I am using csh shell.
% whoami
Whoami options
whoami command only has two options. --help and --version.
% whoamin --help
The output is the same information as man whoami.
% whoami --version
While --version will show you the version of whoami in your system
The Whoami command has the same output as command id -un. It also prints the username of the current user.
% id -un
The whoami command is also used when you are doing su
activity (switch user). This command can confirm that you are logged in using the correct user. Whoami is different from who command. the who command display all logged in user while whoami not. When you are switching user, whoami will report the current user which is the owner of the session, while the who command will report you the original user before you are switching user.
The whoami command can be used to verify sudo privilege of a user. Run sudo whoami
and the output displays as "root" then the user has sudo access.
Conclusion
In this short tutorial, we learn about whoami command in Linux and its usage. Also learned about the difference between whoami and who command.