Linux / Unix: whoami Command Examples

by on January 25, 2012 · 0 comments· LAST UPDATED January 25, 2014

in , , ,

whoami command

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.

whoami command details
DescriptionShow your login name
Category
Difficulty
Root privilegesNo
Estimated completion time1m
Contents
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.

Purpose

Displays your login name without root authority.

Syntax

The basic syntax is as follows:

whoami
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

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" ]
then
     echo "Welcome back admin. Updating repo data in $HOME/foo/bar..."
     ## your commands for admin user ##
fi
 

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:

vivek
See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: