LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   "who am i " command (https://www.linuxquestions.org/questions/linux-newbie-8/who-am-i-command-4175607132/)

chetanraj 06-01-2017 04:35 PM

"who am i " command
 
i tried running "who am i" command but there is no output,but my professor has "howard pts/2 2017-05-29 10:43 (:0)"
2.when i run whoami command its shows as tty not pts/
Thank you

Shadow_7 06-01-2017 04:58 PM

One command is $(whoami), then other is $(who) with parameters "am i".

$ whoami

$ who am i

chetanraj 06-01-2017 10:31 PM

BUT "WHOAMI" is giving me the username, but no output for "who am i"

frankbell 06-01-2017 10:39 PM

Quote:

no output for "who am i
There is a Linux command who. Who am i is not a valid form of that command, as am i are not valid arguments for who. Consequently, who am i is not a valid command. See man who for more about the who command.

(The who command is completely different from the whoami command.)

To put it another way, who am i asks as question that Linux cannot interpret, so, in your case at least, no answer is provided. It understands the who, but it doesn't understand the am i.

It's sort of like asking, "What's your favorite make of automobile: Dell, Lenovo, or Zareason?"

(I'm mildly surprised you didn't get something like I got:

Code:

# who am i
[username] pts/1

My Slackware system just ignored the am i, knowing they weren't valid, and responded as if the command had been a simple who.)

Indeed, we were talking about this at my LUG dinner tonight. Learning the command line is like learning a new language. It has nouns, verbs, and modifiers (nouns=files and folders, verbs=commands, modifiers=arguments to commands) and especially it has a very strict syntax. A human being can usually understand what you mean if you misspell a word or use the wrong tense of a verb; a computer cannot.

The darn things xpect you to speek to them correctly, just as crossword puszles expect you to splet words rite.

Shadow_7 06-01-2017 11:24 PM

The man page for whoami basically says that it is equivalent to $(id -un)

$ id -un
$ whoami

versus something like

$ who -a

or

$ id

frankbell 06-01-2017 11:44 PM

Quote:

$ id -un
$ whoami

versus something like

$ who -a

or

$ id
Thanks, Shadow_7, I learned something. That makes my day.

pan64 06-02-2017 02:16 AM

man who on my ubuntu tells:
Code:

SYNOPSIS
      who [OPTION]... [ FILE | ARG1 ARG2 ]

ARG1 ARG2 can be: am I, or mom likes or anything else, and is identical to -m
Code:

If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.

frankbell 06-02-2017 09:00 PM

Thanks. A nice tidbit!

Quote:

Code:

If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.

I see that who without additional arguments returns all logged in users; who -m seems to return the user that invoked who.

From the man page:

Code:

-m    only hostname and user associated with stdin
With that switch, it performs the same function as whoami, but returns a bit more information (pts, etc.)

sgrlscz 06-05-2017 06:15 AM

Quote:

Originally Posted by frankbell (Post 5718515)
Thanks. A nice tidbit!



I see that who without additional arguments returns all logged in users; who -m seems to return the user that invoked who.

From the man page:

Code:

-m    only hostname and user associated with stdin
With that switch, it performs the same function as whoami, but returns a bit more information (pts, etc.)

Not exactly. 'whoami' prints the username for the effective userid, 'who am i' prints the user associated with stdin. For example, if you use 'su' or 'sudo' to switch to a different user, 'whoami' and 'who am i' will be different. They distinguish between who you logged in as (who am i) vs. the user you are right now (whoami).

Thomas Baeckeroot 08-20-2017 04:40 PM

ls -l `tty`
 
WORKAROUND:
Code:

ls -l `tty` | awk '{print $3}'
This works as replacement from
Code:

who am i | awk '{print $1}'
and may look like what you are looking for.

Explanation:

On many systems "who am i" is equivalent to "who -m". (I believe this works for most Linux but not all Unix? To be confirmed…)
The problem here is that with some terminals, "who -m" returns nothing!

Example #1 run from a xfce4-terminal on Mint 18+, after "sudo su"
Code:

Pegasus ~ # whoami
root
Pegasus ~ # who am i
thomas  pts/1        2017-08-19 11:15 (:0.0)
Pegasus ~ # who -m
thomas  pts/1        2017-08-19 11:15 (:0.0)
Pegasus ~ # who
thomas  tty8        2017-08-19 10:18 (:0)
thomas  pts/1        2017-08-19 11:15 (:0.0)
thomas  pts/5        2017-08-19 16:16 (:0.0)
Pegasus ~ # who am i | awk '{print $1}'
thomas
Pegasus ~ #

but
Example #2 from a gnome-terminal (same computer, same commands)
Code:

Pegasus ~ # whoami
root
Pegasus ~ # who am i
Pegasus ~ # who -m
Pegasus ~ # who
thomas  tty8        2017-08-19 10:18 (:0)
thomas  pts/1        2017-08-19 11:15 (:0.0)
thomas  pts/5        2017-08-19 16:16 (:0.0)
Pegasus ~ # tty
/dev/pts/5
Pegasus ~ # ls -l `tty`
crw--w---- 1 thomas tty 136, 5 août  20 23:36 /dev/pts/5
Pegasus ~ # ls -l `tty` | awk '{print $3}'
thomas
Pegasus ~ #

This seems to be a consequence of gnome-terminal not adding utmp entries…


All times are GMT -5. The time now is 10:58 PM.