The whoami command writes the user name (i.e., login name) of the owner of the current login session to standard output. Standard output is, by default, the display screen, unless redirected to a file, printer, etc. whoami is particularly useful when using shells such as ash and sh that do not show the name of the current user in the command prompt (a short text message at the start of the command line on an all-text display). It is also useful for confirming the current owner of a session after using the su (i.e., substitute user) command, which changes the owner of the session without the original owner having to first log out. A shell is a program that provides the traditional, text-only user interface for Unix-like operating systems. Its primary function is to read commands that are typed into a console (i.e., an all-text display mode) or terminal window (an all-text window in a GUI) and then execute (i.e., run) them. The formal syntax for whoami is:
When used without any options or redirection, as it usually is, i.e.,
and followed by pressing the ENTER key, whoami displays on the monitor screen the user name of the owner of the current session. There are only two options for whoami: --help and --version. The former outputs the very brief description that is contained in the man (i.e., built-in system manual) pages, and the latter outputs the number of the version currently installed on the system. whoami produces the same result as the id command (which by default provides more detailed information about the current user than does whoami) when id is used with its -u and -n options, i.e.,
The -u option tells id to provide only the identification for the current owner of the session, and the -n option tells it to present that identification as the user name instead of as a number. The who command differs from whoami in that it provides a list of all users currently logged into the system as well as additional information about each of those users (including login times and terminal numbers). It also differs in that, in the event of a change in ownership of a login session through the use of the su command, it reports the original owner of the session, whereas whoami provides the user name of the effective (i.e., current) owner of the session. |
Created November 1, 2004. Updated April 30, 2007.
Copyright © 2004 - 2007 The Linux Information Project. All Rights Reserved.