• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

whoami Command in Linux (Find Logged In User)

Written by Rahul, Updated on December 21, 2020

whoami is an basic Unix/Linux command used to find username associated with current effective user id. This is generally used to identify the current logged in user in a shell. This command is also useful in shell scripts to identify the user id from which the script is running.

Syntax:

whoami [OPTION]...

whoami Command in Linux

Simply type the ‘whoami’ on command prompt to find logged in user in current shell.

whoami 

root

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.

id -un 

root

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.

1
2
3
4
5
#!/bin/bash
 
if [ `whoami` == 'root' ]; then
       echo "Warning! You are running this script as root user"
fi

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.

whoami 

Output:>  root 

who am i 

Output:>  root     pts/14       2020-12-21 23:13 (150.242.65.112) 

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’.

whoami 

Output:>  root 

who am i 

Output:>  rahul     pts/14       2020-12-21 23:16 (150.242.65.112) 

Conclusion

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

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy