What is the difference between logname and whoami?

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 su or sudo).
  • Example: If you switch to another user using su, running whoami will 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, running logname will still show the original user's name.

Summary

  • Use whoami to find out the current effective user.
  • Use logname to find out the original user who logged into the session.

0 Comments

no data
Be the first to share your comment!