The logname and whoami commands both provide information about the user, but they serve slightly different purposes and can yield different results depending on the context:
whoami
- Purpose: Displays the effective username of the user currently executing the command.
- Output: Shows the username associated with the current user session, which may change if the user has switched accounts (e.g., using
suorsudo). - Example: If you switch to another user using
su, runningwhoamiwill show the new user's name.
logname
- Purpose: Displays the original username of the user who logged into the terminal session.
- Output: Shows the username of the user who initiated the session, regardless of any subsequent user changes.
- Example: If you switch to another user using
su, runninglognamewill still show the original user's name.
Summary
- Use
whoamito find out the current effective user. - Use
lognameto find out the original user who logged into the session.
