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|
|Description||Show your login name|
|Estimated completion time||1m|
Displays your login name without root authority.
The basic syntax is as follows:
To simply display your username, type:
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
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
- /etc/passwd file
- whoami(1) Linux/Unix command man page
- Man pages – passwd(5)