[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 12, 2023

How to use Whoami Command

How To Use Whoami Command

In this article, we will cover the whoami command.

As its name suggests, the whoami command prints the user name of the effective user ID. In other words, it displays the name of the currently logged-in user.

 

How to Use the whoami Command

The syntax for the whoami command is as follows:

whoami [OPTION]

To display the name of the currently logged user, invoke the command without any options:

whoami

Output similar to the following will be displayed on the screen, showing the name of the user invoking the command:

root

You can use the whoami command in shell scripts to check the user’s name running the script.

Here is an example using an if statement to compare the user’s name running the script with a given string.

if [[ "$(whoami)" != "any_name" ]]; then
  echo "Only user 'any_name' can run this script."
  exit 1
fi

If the user name does not match the given string, the script will echo a message and exit.

The whoami command is also handy for verifying the user’s name after switching to another user with the su command.

whoami does not accept arguments. If you pass an argument, the command prints an error message:

whoami: extra operand ‘anything’
Try 'whoami --help' for more information.

The whoami command accepts only two options:

  • -h, –help – Display a help message and exit.

  • -V, –version – Shows the version information and exit.

 

Alternative Commands

Running the id command with the -un options produces the same output as running whoami:

whoami [OPTION]

Use the id command to obtain more information about a given user.

The $USER environment variable contains the name of the logged-in user:

echo $USER

Conclusion

The whoami command is a compound of the words “Who am I?” and prints the name of the user associated with the current effective user ID.

Keep reading
How to Whitelist/Allow an IP address on CentOS, Redhat, Fedora Linux Server
February 21, 2023

How to Whitelist/Allow an IP address on CentOS, Redhat, Fedora Linux Server

How to Whitelist/Allow an IP address on CentOS, Redhat, Fedora Linux Server Steps to Allow incoming and outgoing connection in IPtables Firewall is given below. How to Whitelist/Allow Incoming connection from an IP address Login into your Linux server via SSH as ‘root’ user Run the command…

Read article
How to use iptables
February 21, 2023

How to use iptables

How to use iptables The user-space application program iptables allows configuring the tables provided by the Linux kernel firewall, as well as the chains and rules it stores. The kernel module currently used for iptables only applies to IPv4 traffic, to configure firewall rules for IPv6…

Read article
How to install java on CentOs.
February 3, 2023

How to install java on CentOs.

How To Install Java On CentOs. First update all packages. Use these command: 2. Install OpenJDK package with these comand: 3. Install OpenJDK-devel package: 4. Check if the package is installed properly through rpm tool: 5. Now check the java version: This is how to install Java in five steps.

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00