Skip to main content

Command Palette

Search for a command to run...

Cheat Sheet #day55 - whoami

Published
1 min read
Cheat Sheet #day55 - whoami

whoami Command Cheatsheet

The whoami command is used to display the current logged-in user’s username. It is a simple yet useful command, particularly for scripting and troubleshooting.

Syntax

whoami

Description

  • Purpose: Returns the username of the current user.

Examples and Use Cases

Display Current User

whoami
  • Outputs the username of the currently logged-in user (e.g., john).

Use in Scripts

You can use whoami in scripts to dynamically reference the current user. For example:

#!/bin/bash
echo "Current user is: $(whoami)"
  • This script will print the current user’s name.

Check User Privileges

Combine whoami with id to display user and group information:

whoami
id -u $(whoami)
  • Outputs the user ID of the current user.

Options

whoami has no options. It simply returns the username.

Additional Information

  • Man Page: For more details, you can refer to the whoami man page:

      man whoami
    

This cheatsheet provides a quick reference to the whoami command. Let me know if you need more information or additional examples!

Cheat Sheets

Part 1 of 50

These cheat sheets are designed to be quick reference materials, offering condensed information, tips, and best practices in a easy to understand format.

More from this blog

Cloud Tuned

621 posts

Your starting point for anything cloud: AWS, Azure, GCP, Serverless, Architecture, Hybrid Cloud, Systems Design and other Information Technology topics.