Skip to content

Linux whoami Guide

Mattscreative edited this page Nov 20, 2025 · 2 revisions

👤 Linux whoami Guide

Complete beginner-friendly guide to whoami on Linux, covering Arch Linux, CachyOS, and other distributions including user identification, current user information, and system user checks.


📋 Table of Contents

  1. Understanding whoami
  2. whoami Usage
  3. Related Commands
  4. Practical Examples
  5. Troubleshooting

🎯 Understanding whoami

What is whoami?

whoami displays current username.

Uses:

  • User identification: See who you are
  • Scripts: Check current user in scripts
  • Troubleshooting: Verify user context
  • Security: Confirm user identity

Why it matters:

  • Clarity: Know current user
  • Scripts: User-aware scripts
  • Debugging: Troubleshoot user issues

👤 whoami Usage

Basic Usage

Display username:

# Show current user
whoami

# Output: username

In Scripts

Use in scripts:

#!/bin/bash
USER=$(whoami)
echo "Current user: $USER"

🔍 Related Commands

who

Show logged in users:

# Show who's logged in
who

# Show with details
who -a

id

User information:

# Show user ID
id

# Show specific user
id username

# Show groups
id -Gn

w

Show users and activity:

# Show logged in users
w

# Show specific user
w username

💡 Practical Examples

Check User in Script

Script example:

#!/bin/bash
if [ "$(whoami)" != "root" ]; then
    echo "This script must be run as root"
    exit 1
fi

User Context

Verify user:

# Check current user
whoami

# Check if root
if [ "$(whoami)" = "root" ]; then
    echo "Running as root"
fi

🔧 Troubleshooting

whoami Not Found

Check installation:

# Check whoami
which whoami

# Usually in coreutils
# Install if missing
sudo pacman -S coreutils

📝 Summary

This guide covered whoami usage, user identification, and related commands for Arch Linux, CachyOS, and other distributions.


🔗 Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally