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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-01-2017, 05:35 PM
|
#1
|
LQ Newbie
Registered: Jun 2017
Posts: 3
Rep: 
|
"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
|
|
|
06-01-2017, 05:58 PM
|
#2
|
Senior Member
Registered: Feb 2003
Distribution: debian
Posts: 4,137
|
One command is $(whoami), then other is $(who) with parameters "am i".
$ whoami
$ who am i
|
|
|
06-01-2017, 11:31 PM
|
#3
|
LQ Newbie
Registered: Jun 2017
Posts: 3
Original Poster
Rep: 
|
BUT "WHOAMI" is giving me the username, but no output for "who am i"
|
|
|
06-01-2017, 11:39 PM
|
#4
|
LQ Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,766
|
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-02-2017 at 12:07 AM.
Reason: Clarity
|
|
|
06-02-2017, 12:24 AM
|
#5
|
Senior Member
Registered: Feb 2003
Distribution: debian
Posts: 4,137
|
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.
|
06-02-2017, 12:44 AM
|
#6
|
LQ Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,766
|
Quote:
$ id -un
$ whoami
versus something like
$ who -a
or
$ id
|
Thanks, Shadow_7, I learned something. That makes my day.
|
|
|
06-02-2017, 03:16 AM
|
#7
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,652
|
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.
|
06-02-2017, 10:00 PM
|
#8
|
LQ Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,766
|
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 10:02 PM.
|
|
|
06-05-2017, 07:15 AM
|
#9
|
Member
Registered: Aug 2008
Posts: 123
Rep:
|
Quote:
Originally Posted by frankbell
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).
|
|
|
08-20-2017, 05:40 PM
|
#10
|
LQ Newbie
Registered: Aug 2017
Location: Lausanne
Posts: 2
Rep: 
|
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 05:45 PM.
Reason: nicer, clearer
|
|
|
All times are GMT -5. The time now is 05:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|