User identity queries in UNIX: Which command displays information about the current user in a human-friendly form (commonly showing login name, terminal, and time)?

Difficulty: Easy

Correct Answer: who am i

Explanation:


Introduction / Context:
When working on multi-user UNIX systems, it is useful to confirm which account you are using and the terminal or remote session you occupy. Multiple commands provide identity or environment information, and choosing the right one depends on what detail you need.



Given Data / Assumptions:

  • You want a readable summary of your login identity and terminal.
  • You are in a typical shell session (local or remote).
  • Standard userland utilities are available.


Concept / Approach:

The who command reports logged-in users. With the am i arguments, it returns details of the current session: username, terminal, login time, and possibly source host. Alternatives like id print UIDs/GIDs numerically, and pwd prints the present working directory, not user identity. which only locates executables in PATH.



Step-by-Step Solution:

Run who am i in the shell.Read the output fields: username, TTY/PTS, login time, optional remote host.Use id for UID/GID details if needed (id -un for username only).Combine with tty to see the device file for your terminal.Use who -m (on some systems) as an equivalent to who am i.


Verification / Alternative check:

Compare who am i output with environment variables like $USER and $LOGNAME, and with id -un for consistent identity information. On SSH, check last or w for session history and current processes.



Why Other Options Are Wrong:

a: which shows where a command binary resides, not user identity.

b: pwd prints your current directory path.

c: i /4 is not a standard UNIX command.

e: Not applicable because who am i is correct for user/session info.



Common Pitfalls:

Assuming $USER always reflects effective UID; in sudo contexts, id and who may reflect different identities; misreading who output fields when connected via remote TTYs.



Final Answer:

who am i

More Questions from Linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion