Linux logname Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux logname Guide
Complete beginner-friendly guide to logname on Linux, covering Arch Linux, CachyOS, and other distributions including login name display, user identification, and username retrieval.
Table of Contents
logname Basics
Show Login Name
Basic usage:
# Show login name
logname
# Output: username
Current User
Login user:
# Login username
logname
# Shows original login username
Login Name
Original Login
Login username:
# Original login
logname
# Shows username of original login
After su
After switching:
# After su
su otheruser
logname
# Still shows original login name
User Identification
Compare with whoami
Difference:
# logname vs whoami
logname # Original login
whoami # Current user
# After su:
# logname = original user
# whoami = current user
Script Usage
In Scripts
Use in scripts:
#!/bin/bash
ORIGINAL_USER=$(logname)
CURRENT_USER=$(whoami)
echo "Original login: $ORIGINAL_USER"
echo "Current user: $CURRENT_USER"
Troubleshooting
logname Not Found
Check installation:
# logname is part of coreutils
# Usually pre-installed
# Check logname
which logname
Summary
This guide covered logname usage, login name display, and user identification for Arch Linux, CachyOS, and other distributions.
Next Steps
- whoami Guide - Current user
- id Guide - User and group IDs
- who Guide - Logged in users
- logname Documentation:
man logname
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.