LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2017, 04:35 PM   #1
chetanraj
LQ Newbie
 
Registered: Jun 2017
Posts: 3

Rep: Reputation: Disabled
"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
 
Old 06-01-2017, 04:58 PM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

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

$ whoami

$ who am i
 
Old 06-01-2017, 10:31 PM   #3
chetanraj
LQ Newbie
 
Registered: Jun 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
BUT "WHOAMI" is giving me the username, but no output for "who am i"
 
Old 06-01-2017, 10:39 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
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.

Last edited by frankbell; 06-01-2017 at 11:07 PM. Reason: Clarity
 
Old 06-01-2017, 11:24 PM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

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

$ id -un
$ whoami

versus something like

$ who -a

or

$ id
 
1 members found this post helpful.
Old 06-01-2017, 11:44 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
$ id -un
$ whoami

versus something like

$ who -a

or

$ id
Thanks, Shadow_7, I learned something. That makes my day.
 
Old 06-02-2017, 02:16 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
1 members found this post helpful.
Old 06-02-2017, 09:00 PM   #8
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
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.)

Last edited by frankbell; 06-02-2017 at 09:02 PM.
 
Old 06-05-2017, 06:15 AM   #9
sgrlscz
Member
 
Registered: Aug 2008
Posts: 123

Rep: Reputation: 84
Quote:
Originally Posted by frankbell View Post
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).
 
Old 08-20-2017, 04:40 PM   #10
Thomas Baeckeroot
LQ Newbie
 
Registered: Aug 2017
Location: Lausanne
Posts: 2

Rep: Reputation: Disabled
Lightbulb 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…

Last edited by Thomas Baeckeroot; 08-20-2017 at 04:45 PM. Reason: nicer, clearer
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How could a computer technician use the "top" command with "ps" and "kill" to investigate how a system is misbehaving? geckono1 Linux - Newbie 13 07-03-2016 07:51 AM
Centos Server Failed @ Bootup: Missing "/sbin/blkid" & "fsck" command not found beagle7 Linux - Newbie 4 08-24-2012 01:33 AM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 04:23 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration