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 |
Category | N/A |
Difficulty | Easy |
Root privileges | No |
Estimated completion time | 1m |
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:
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
- /etc/passwd file
- whoami(1) Linux/Unix command man page
- Man pages – passwd(5)
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |