Difference between who and whoami commands

command linewhowhoami

The man page description of who command is
who - show who is logged on

But there exists a similar command whoami. The man page description of whoami is

whoami - print effective userid

Can anyone explain what exactly these commands do ? How are they different from each other ?

Best Answer

I am logging in as root in my shell and typing who and this is the output.

who
root     tty1         2014-08-25 14:01 (:0)
root     pts/0        2014-09-05 10:22 (:0.0)
root     pts/3        2014-09-19 10:08 (xxx.xxx.edu)

It effectively shows all the users that have established a connection.

ssh ramesh@hostname

Running who again will result in another entry for the user ramesh.

who
root     tty1         2014-08-25 14:01 (:0)
root     pts/0        2014-09-05 10:22 (:0.0)
root     pts/3        2014-09-19 10:08 (xxx.xxx.edu)
ramesh   pts/4        2014-09-19 12:11 (xxx.xxx.edu)

Inside the root shell, I just do su ramesh and then run whoami. It will give me the current user, ramesh, as the output.

Effectively, who gives the list of all users currently logged in on the machine and with whoami you can know the current user who is in the shell.

Related Question