Generally, you will find that the user name has been displayed at the console command prompt. However, some shells do not display your username by default, such as csh. Therefore, this command should be used on shell terminals that cannot display the user name back.
How to run whoami
To run this command, you only need to enter whoami. In the following example, we use the csh shell terminal.
% Whoami
Whoami Parameter options
This command only has two parameter options:-help and-version.
% Whoamin-help
The following option outputs the same information as the man whoami command.
% Whoami-version
The difference is that-version displays the version information of the whoami command on your system.
Similarity
The whoami command and id-un have the same output. They all display the User Name of the current user.
% Id-un
Conclusion
The whoami command is also used when you use the su command (switch user) to confirm whether the user name for logon is correct. The whoami and who commands are different. The who command displays all the usernames that have been logged on, but the whoami command is not. When you switch users, the whoami command displays the current user to which the session belongs, and the who command displays the source user before the switch.
Ten Linux commands that are rarely known-Part 2
Ten Linux commands that are rarely known-Part 3
11 Linux commands that are rarely known but useful
Linux Command cd
Cat for Linux commands
Linux Command alias/unalias
Linux Command Parsing: su root and su-root