Syntax:

whoami Command in Linux

Simply type the ‘whoami’ on command prompt to find logged in user in current shell. The above output shows that you are logged in with user ‘root’ in current shell. The same details can be find with id -un command in Linux. Let’s write a small bash shell script and check if script is running as root user or not. This is very useful to warn user that the script is running as root user.

Difference Between whoami and who am i Command

Both the commands whoami and who am i are used to get logged in username in Linux system. The username is defined in passwd file associate with effective user id. When a user login as root on the network, then both whoami and who am i commands will return root. But, when you logged in as another user (eg: rahul) and switched to root user (su – root). The whoami will show root but who am i will show the originally logged in user ‘rahul’.

Conclusion

In this tutorial, you have learn about Linux whoami command as well as difference with “who am i” command.