How does `whoami` differ from `id -un`?

QuestionsQuestions8 SkillsProYour First Linux LabDec, 08 2025
0121

The whoami command and id -un command both return the username of the current user, but they do so in slightly different ways:

  • whoami: This command simply outputs the username of the user currently logged in to the terminal session.

  • id -un: This command is part of the id utility, which provides more detailed information about the user. The -u option specifies to return the user ID, and the -n option specifies to return the name associated with that ID. Thus, id -un also outputs the username of the current user.

Example:

Both commands will typically yield the same result:

whoami
# Output: alice

id -un
# Output: alice

In summary, while both commands provide the same output, id can offer more detailed user information if needed. If you have more questions, let me know!

0 Comments

no data
Be the first to share your comment!