Hi
The answer to this question is the 'whoami' command.
The 'who' command returns all the users currently logged in to the system.
The 'id' command returns the current user's id (uid), their group id (gid) and all groups they are members of.
I am not aware of the username command!
Regards
AA
I'm liking the "id" command, as well as the "whoami" command.
Granted, the "id" command displays userid, groupid, etc. information.
Had the query been phrased as "...displays ONLY the username ...",
then the "whoami" command certainly would have the only
acceptable choice. However, I do understand your reasoning.
Thanks for responding!!!
You forgot this one: w
(Yes, just w. Look for the tty* entry.)
Tracy, I didn't forget the 'w' command.
I deliberately left it out, to entice you to
weigh in - and it worked
And you are saying that the 'w' command,
by itself, will NOT display the username
of the currently logged in user, right?
I would provide a screenshot of what the
'w' command actually displays, but I don't
want to deprive other readers from looking
at this on their own system.
If you run the w command without any options, it displays the following information:
Output columns:
abhidd, I agree with you 101% that the 'w' command, without any options, displays all of the columns. However, there's not a single piece of information, for any user, in either of those columns - especially for what the initial query is asking for: currently logged in user.
Thanks for your response!!!
The who command displays details regarding users currently logged into the system, detailing usernames, terminal sessions, login timestamps, and, when applicable, remote host data. This information is derived from parsing system files such as /var/run/utmp and /var/log/wtmp, which track login and logout activities. In contrast, whoami provides a straightforward display of the current user's effective username, achieved through a direct query of the process's Effective User ID (EUID).
I will go with "whoami" command, This command specifically displays the username of the currently logged-in user. ofcourse you can also use id -un
Regards
Gopinath
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.