whoami command in Linux with Examples

whoami command outputs the username that the user is working under.

The whoami command in Linux is used to display the username of the current user who is logged in. It provides a simple way to retrieve the current user’s name. Here are some examples of using the whoami command:

whoami command in Linux with Examples

On the man page, the describes it

  • whoami – print effective userid.
  • man whoami – More details information.

whoami command in Linux with Examples

Print the username of the current user:

$ whoami

Use the command substitution to assign the username to a variable:

username=$(whoami)
echo "Current user: $username"

Conclusion

These are some examples of using the whoami command in Linux. It is helpful in shell scripts or when you need to know the current user’s name for various purposes.

whoami command is a simple command in Linux. It is the most popular in-use terminal Linux print effective userid. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.