Linux “who am i” command

Posted by Planet Malaysia on February 27, 2009

advertisement

Linux “who” command is use to show who is logged on the Linux server.

For an example:

planetmy:~ # who am i
user1 pts/0 Feb 27 08:14 (192.168.1.145)

planetmy:~ # who am i|cut -d! -f2|cut -d\ -f1
user1

Yesterday, one of the Linux box show an empty result with “who am i” or “who” command.

If you look at “man who“,

If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common. If ARG1 ARG2 given, -m presumed: `am i’ or `mom likes’ are usual.


Solution:
1. Make sure /var/run/utmp exist?
2. Make sure /var/run/utmp update if any user login.
3. Rename existing /var/run/utmp and create an empty /var/run/wtmp with same permission.

Linux who am i command

Solve your problem?

Probably you may ask why “who am i” and not “whoami“? Try login with normal user and type “sudo su -” and enter “who am i” and “whoami” command and you will notice the differential.

Possibly Related Posts:


Comments

4 Responses to “Linux “who am i” command”

  1. Mohd Shakir Zakaria on March 9th, 2009 8:34 am

    Why make life difficult? Just use whoami instead of who am i|cut -d! -f2|cut -d\ -f1
    They give the same result.

  2. Planet Malaysia on March 10th, 2009 10:24 am

    I think you missed out last sentence. Why use “who am i” instead of “whoami” command.

  3. Noah on June 12th, 2010 5:12 pm

    but whats the difference between whomai and ‘who am i ”
    http://www.linux-commands.com/linux-whoami/ says that they are same thing ? but their output is slightly different from each other

  4. rezapb on October 2nd, 2010 2:39 am

    Thanks for the post. I am having this problem too, but only when I am logged directly onto the box. If I am logged in remotely, ‘who am i’ works just fine.

    Noah: As Malaysia indicated, the difference is that when you are executing a script as root via sudo, ‘whoami’ will show ‘root’, but ‘who am i’ will show your actual user name. Actually, ‘who am i’ is actually the same as ‘who -m’, while ‘who’ by itself will show ALL of the users logged in, ‘who -m’ will show only the user associated with stdin.

    Hope that helps…

Leave a Reply




Planet Malaysia

  • Follow us on Twitter


  • web www.planetmy.com