I'm trying to find a Linux equivalent of running who -m in Unix. In Unix, who -m gives the first user ID you used to log in, before starting any new shell sessions through su, etc.

The -m switch to who has a different effect in Linux, and I'm unable to find anything relevant to my needs in the man pages so far.

  • I FOUND A WORKAROUND! ls -l `tty` | awk '{print $3}' returns the expected output consistently across Linux systems, while who -m works on some but not others. – lahfordie Mar 3 '17 at 7:07
  • Ideally I would still like to know a who way. – lahfordie Mar 3 '17 at 7:08

Update: My answer (who am i) is correct, your terminal is either broken or not configured correctly to support the functionality.

Based on the comments, I've done some more research and I asked a friend to help. You don't say which terminal you are using but it's likely doing the same thing as gnome-terminal.

In respect of gnome-terminal* when the terminal is started, it does not update the utmp file. This appears to be a design decision. Later when who reads utmp to find out the relevant information it's not there so it just exits and prints nothing.

* I tries xterm, konsole and ssh to various distros.

You want who am i which prints the invoking user as opposed to whoami which tells you the username of the current effective user

If given two non-option arguments, 'who' prints only the entry for the user running it (determined from its standard input), preceded by the hostname. Traditionally, the two arguments given are 'am i', as in 'who am i'.

That is buried in info coreutils 'who invocation' So interestingly (on a linux coreutils based system) who xyzzy plugh works as well.

  • Logged in on my local GNOME console, who mom likes prints nothing. – Michael Hampton Mar 3 '17 at 6:37
  • Thanks! I see now that my Linux sample size should have been larger. I tried a couple more and found one that works in the way you explained: who am i and who -m both return the same output on that system actually. However, on the first ones I looked at, they return no output at all. root@server:/root $ who am i root@server:/root $ who -m root@server:/root $ which who /usr/bin/who – lahfordie Mar 3 '17 at 6:42
  • The man page on the systems where it doesn't work shows, for option -m: -m Output only information about the current terminal. There is no info in the man page for who am i on those sytems. info who gives the expected info, but it doesn't behave that way when executed. – lahfordie Mar 3 '17 at 6:47
  • The other man page (one is man 1p, the other is man 1), shows this for -m: -m only hostname and user associated with stdin. Either way, blank line haha. – lahfordie Mar 3 '17 at 6:49
  • @MichaelHampton who am i and who mom likes work as expected on C6.8, C7.3 , F25 (knosole) and Ubuntu 16.04 – user9517 Mar 3 '17 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.