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 theidutility, which provides more detailed information about the user. The-uoption specifies to return the user ID, and the-noption specifies to return the name associated with that ID. Thus,id -unalso 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!
