whoami command

In this tutorial we will learn about whoami command in Linux / Unix system. We will also read about its use and advantage. Its best use is in shell like sh,ash and ksh where username is not seen in command prompt.

Introduction Of whoami Command

The whoami command print the user name associated with user id which is login in current session.It is similar to command id -un.
The whoami command is available in Linux and Unix like Operating Systems.

whoami Command Use And Advantage

To use whoami command , simply run the command whoami . It will show the user name of currently working username in current session.

Syntax:

whoami

Note: The whoami command is also available in Windows (Read this Microsoft link for information)

See given below figure: whoami command in Linux bash shell

whoami command

Advantage Of whoami Command

As you have seen in above figure, in BASH shell , we can easily see the username.In some shell, you will only see $ sign .It means non-root user login in shell terminal.

If in your terminal,if you see only $ sign. You can not confirm you are login with which user name. In that case you can use whoami command

I have selected Bourne Shell (sh) and korn shell (ksh) to illustrate the example.
Notice the $ sign in both Bourne Shell (sh) and korn shell (ksh) .

whoami command
whoami command

Note: The whoami command only has available two options that is ‘help’ and ‘version’.
Find the given below commands.

whoami --help 

and 
whoami --version

Read Some More Articles

One Comment

  1. If you cange to a different user after loggin in, you could use` #who am i` to get the login info. Similar to the output of `who’ but only gives info for the current user. I am integrating this command into my bash history monitoring setup so that if somebody runs “su – ” to change to root in my server, I can have a trail of who actually ran that command.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.