Linux / Unix: whoami Command Examples

I am a new Linux and Unix system user. How do I listing my own username? How can I display my login name on Linux or Unix-like systems?

You need to use the whoami command to display your login name. This command display the user name associated with the current logged in user at your console.[donotprint]

whoami command details
Description Show your login name
Root privileges No
Estimated completion time 1m
[/donotprint]This command is only useful if you are using a shared Linux/Unix terminal at your school, library or home, to find out whether or not it is your account that you are using it.


Displays your login name without root authority.


The basic syntax is as follows:

whoami --version
whoami --help

whoami command examples

To simply display your username, type:
$ whoami
Sample outputs:

Animated gif 01: Displaying your username using whoami and id commands

You can use this command in a shell script as follows:

## if username is admin, do something ##
if [ "$(whoami)" == "admin" ]
     echo "Welcome back admin. Updating repo data in $HOME/foo/bar..."
     ## your commands for admin user ##

Recommend alternative to whoami command

The whoami command has been obsoleted by the id command. You need to use the following command which is equivalent to id -un:
$ id -un
Sample outputs:

See also
  • /etc/passwd file
  • whoami(1) Linux/Unix command man page
  • Man pages – passwd(5)
Category List of Unix and Linux commands
File Management cat
Network Utilities dighostip
Package Manager apkapt
Processes Management bgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searching whereiswhich
User Information idgroupslastlastcommlognameuserswwhowhoamilid/libuser-lidmembers

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts