Skip to main content

Command documentation sourced from the linux-command project This comprehensive command reference is part of the linux-command documentation project.

uname - Display System Information

The uname command is a fundamental utility in Unix/Linux systems that provides essential system information including kernel name, network hostname, kernel release and version, hardware architecture, processor type, and operating system details. It serves as a critical tool for system identification, compatibility checking, system administration, and automated script execution where system-specific information is required for conditional logic and platform-specific operations.

Basic Syntax

uname [OPTIONS]
uname [-snrvmoapi] [--help] [--version]

Complete Options Reference

Information Display Options

  • -a, --all - Print all available information
  • -s, --kernel-name - Print kernel name (default)
  • -n, --nodename - Print network node hostname
  • -r, --kernel-release - Print kernel release version
  • -v, --kernel-version - Print kernel version details
  • -m, --machine - Print machine hardware name
  • -p, --processor - Print processor type (often unknown)
  • -i, --hardware-platform - Print hardware platform (often unknown)
  • -o, --operating-system - Print operating system name

Help and Version

  • --help - Display help message and exit
  • --version - Output version information and exit

Output Format Details

uname -a (All Information) Format

When using -a, the output format is:

kernel_name hostname kernel_release kernel_version hardware_platform processor_type operating_system

Example:

Linux workstation 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Breaking down the components:

  • Linux - Kernel name
  • workstation - Network node hostname
  • 5.15.0-52-generic - Kernel release version
  • #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 - Kernel version and build information
  • x86_64 - Machine hardware name
  • x86_64 - Processor type
  • x86_64 - Hardware platform
  • GNU/Linux - Operating system

Kernel Version Breakdown

The kernel version string contains valuable information:

  • 5.15.0 - Main kernel version (major.minor.patch)
  • 52 - Distribution-specific patch level
  • generic - Kernel variant/flavor
  • #58 - Build number
  • SMP - Symmetric Multi-Processing support
  • Thu Oct 13 08:03:55 UTC 2022 - Build timestamp

Usage Examples

Basic System Information Retrieval

Essential System Commands

# Show kernel name (default behavior)
uname
# Output: Linux

# Display complete system information
uname -a

# Get just the hostname
uname -n

# Get kernel release version
uname -r

# Get kernel version details
uname -v

# Get hardware architecture
uname -m

# Get operating system name
uname -o

Hardware Architecture Detection

# Check system architecture
ARCH=$(uname -m)
echo "Architecture: $ARCH"

# Common architecture checks
case $(uname -m) in
x86_64)
echo "64-bit Intel/AMD system"
;;
i386|i686)
echo "32-bit Intel/AMD system"
;;
armv7l)
echo "32-bit ARM system"
;;
aarch64)
echo "64-bit ARM system"
;;
*)
echo "Unknown architecture: $(uname -m)"
;;
esac

# Check for little-endian vs big-endian
if [ $(echo -n "$(uname -m)" | tail -c 1) = "6" ]; then
echo "64-bit little-endian"
elif [ "$(uname -m)" = "x86_64" ]; then
echo "64-bit little-endian"
fi

Kernel Information Analysis

# Extract kernel version components
KERNEL_RELEASE=$(uname -r)
echo "Full kernel release: $KERNEL_RELEASE"

# Get major.minor version
KERNEL_VERSION=$(echo $KERNEL_RELEASE | cut -d. -f1-2)
echo "Kernel version: $KERNEL_VERSION"

# Check if kernel version meets minimum requirement
REQUIRED_VERSION="4.19"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$KERNEL_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
echo "Kernel version is too old. Required: $REQUIRED_VERSION, Found: $KERNEL_VERSION"
exit 1
else
echo "Kernel version is sufficient: $KERNEL_VERSION"
fi

# Parse kernel build information
uname -v | awk '{print $1, $2, $3, $4, $5, $6}'
# Example output: #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022

System Identification and Compatibility

Platform Detection

#!/bin/bash
# Comprehensive platform detection script

detect_platform() {
local kernel=$(uname -s)
local hostname=$(uname -n)
local release=$(uname -r)
local version=$(uname -v)
local machine=$(uname -m)
local processor=$(uname -p)
local platform=$(uname -i)
local os=$(uname -o)

echo "=== System Platform Information ==="
echo "Kernel: $kernel"
echo "Hostname: $hostname"
echo "Release: $release"
echo "Version: $version"
echo "Machine: $machine"
echo "Processor: $processor"
echo "Platform: $platform"
echo "OS: $os"

# Determine Linux distribution
if [ "$kernel" = "Linux" ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "Distribution: $PRETTY_NAME"
elif [ -f /etc/redhat-release ]; then
echo "Distribution: $(cat /etc/redhat-release)"
elif [ -f /etc/debian_version ]; then
echo "Distribution: Debian $(cat /etc/debian_version)"
fi
fi

# Determine virtualization
if grep -q "hypervisor" /proc/cpuinfo 2>/dev/null; then
echo "Virtualization: Yes (hypervisor detected)"
elif [ -d /proc/vz ]; then
echo "Virtualization: OpenVZ"
elif [ -f /sys/class/dmi/id/product_name ]; then
local product_name=$(cat /sys/class/dmi/id/product_name 2>/dev/null)
echo "Product: $product_name"
case "$product_name" in
*VMware*|*VirtualBox*|*QEMU*|*KVM*)
echo "Virtualization: Yes (Virtual machine)"
;;
esac
else
echo "Virtualization: Physical machine"
fi
}

detect_platform

Cross-Platform Compatibility Scripts

#!/bin/bash
# Cross-platform package management

install_package() {
local package_name="$1"
local os=$(uname -s)

case "$os" in
Linux)
# Check for package manager
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y "$package_name"
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y "$package_name"
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y "$package_name"
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -S "$package_name"
else
echo "No supported package manager found"
return 1
fi
;;
Darwin)
if command -v brew >/dev/null 2>&1; then
brew install "$package_name"
else
echo "Homebrew not found"
return 1
fi
;;
FreeBSD)
sudo pkg install "$package_name"
;;
*)
echo "Unsupported OS: $os"
return 1
;;
esac
}

# Architecture-specific operations
download_architecture_specific() {
local base_url="$1"
local file_name="$2"
local arch=$(uname -m)

case "$arch" in
x86_64)
ARCH_SUFFIX="amd64"
;;
i386|i686)
ARCH_SUFFIX="i386"
;;
aarch64)
ARCH_SUFFIX="arm64"
;;
armv7l)
ARCH_SUFFIX="armhf"
;;
*)
ARCH_SUFFIX="$arch"
;;
esac

wget "${base_url}/${file_name}-${ARCH_SUFFIX}.tar.gz"
}

System Administration and Monitoring

System Inventory Script

#!/bin/bash
# Complete system inventory

generate_system_inventory() {
local report_file="/tmp/system_inventory_$(date +%Y%m%d_%H%M%S).txt"

{
echo "=== SYSTEM INVENTORY REPORT ==="
echo "Generated: $(date)"
echo "Hostname: $(uname -n)"
echo "IP Address: $(hostname -I | awk '{print $1}')"
echo ""

echo "=== KERNEL INFORMATION ==="
uname -a
echo ""

echo "=== HARDWARE INFORMATION ==="
echo "Architecture: $(uname -m)"
if [ -f /proc/cpuinfo ]; then
echo "CPU Model: $(grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2 | sed 's/^ *//')"
echo "CPU Cores: $(nproc)"
echo "CPU Threads: $(grep -c processor /proc/cpuinfo)"
fi
echo ""

echo "=== MEMORY INFORMATION ==="
free -h
echo ""

echo "=== DISK INFORMATION ==="
df -h
echo ""

echo "=== NETWORK INTERFACES ==="
ip addr show | grep -E '^[0-9]+:' | while read line; do
interface=$(echo "$line" | cut -d: -f2)
echo "Interface: $interface"
done
echo ""

echo "=== UPTIME ==="
uptime
echo ""

echo "=== RUNNING PROCESSES ==="
ps aux | wc -l | awk '{print "Total processes: " $1}'
echo ""

} > "$report_file"

echo "System inventory saved to: $report_file"
cat "$report_file"
}

generate_system_inventory

System Health Check

#!/bin/bash
# System health monitoring script

system_health_check() {
local status=0

echo "=== SYSTEM HEALTH CHECK ==="
echo "Timestamp: $(date)"
echo "Hostname: $(uname -n)"
echo ""

# Kernel version check
local kernel=$(uname -r)
echo "Kernel: $kernel"

# Check for old kernel (older than 1 year)
local kernel_date=$(uname -v | grep -o '[A-Za-z][A-Za-z][A-Za-z] [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]')
echo "Kernel build date: $kernel_date"
echo ""

# Architecture check
echo "Architecture: $(uname -m)"
echo "Platform: $(uname -i)"
echo ""

# Load average check
local load_avg=$(uptime | awk -F'load average:' '{print $2}' | awk '{print $1}' | tr -d ',')
echo "Load average (1 min): $load_avg"

# Convert load average to integer for comparison
load_int=$(echo "$load_avg" | cut -d. -f1)
if [ "$load_int" -gt 4 ]; then
echo "WARNING: High load average detected!"
status=1
fi
echo ""

# Memory check
local mem_usage=$(free | awk '/^Mem:/ {printf "%.1f", ($3/$2)*100}')
echo "Memory usage: ${mem_usage}%"

if (( $(echo "$mem_usage > 80" | bc -l) )); then
echo "WARNING: High memory usage!"
status=1
fi
echo ""

# Disk space check
local disk_usage=$(df / | awk 'NR==2 {print $5}' | tr -d '%')
echo "Root disk usage: ${disk_usage}%"

if [ "$disk_usage" -gt 85 ]; then
echo "WARNING: High disk usage!"
status=1
fi
echo ""

# Process count check
local proc_count=$(ps aux | wc -l)
echo "Total processes: $proc_count"

if [ "$proc_count" -gt 500 ]; then
echo "WARNING: High process count!"
status=1
fi
echo ""

# Overall status
if [ $status -eq 0 ]; then
echo "✅ System health: GOOD"
else
echo "❌ System health: ISSUES DETECTED"
fi

return $status
}

system_health_check

Integration with Other Tools

Comprehensive System Report

#!/bin/bash
# Generate comprehensive system report

generate_comprehensive_report() {
local output_file="$HOME/system_report_$(date +%Y%m%d).txt"

{
echo "COMPREHENSIVE SYSTEM REPORT"
echo "============================="
echo "Generated: $(date)"
echo "Hostname: $(uname -n)"
echo ""

echo "=== BASIC SYSTEM INFORMATION ==="
uname -a
echo ""

echo "=== HARDWARE SPECIFICATIONS ==="
echo "CPU Information:"
lscpu
echo ""

echo "Memory Information:"
free -h
echo ""

echo "Disk Information:"
df -h
lsblk
echo ""

echo "PCI Devices:"
lspci | head -10
echo ""

echo "USB Devices:"
lsusb
echo ""

echo "=== NETWORK CONFIGURATION ==="
ip addr show
echo ""

echo "Network Interfaces:"
ip link show
echo ""

echo "=== SYSTEM PERFORMANCE ==="
echo "Current Load Average:"
uptime
echo ""

echo "Top Processes by CPU:"
ps aux --sort=-%cpu | head -10
echo ""

echo "Top Processes by Memory:"
ps aux --sort=-%mem | head -10
echo ""

echo "=== SYSTEM LOGS SUMMARY ==="
echo "Recent kernel messages:"
dmesg | tail -10
echo ""

echo "Recent system log entries:"
tail -10 /var/log/syslog 2>/dev/null || journalctl -n 10 2>/dev/null
echo ""

} > "$output_file"

echo "Comprehensive system report generated: $output_file"
}

generate_comprehensive_report

Advanced Scripting Techniques

Conditional System Configuration

#!/bin/bash
# System configuration based on platform detection

configure_based_on_system() {
local os=$(uname -s)
local arch=$(uname -m)
local kernel=$(uname -r)

echo "Configuring for $os $arch"

# Set environment variables based on architecture
case "$arch" in
x86_64)
export ARCH=x86_64
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
;;
i386|i686)
export ARCH=i386
export LIBRARY_PATH=/usr/lib/i386-linux-gnu:$LIBRARY_PATH
;;
aarch64)
export ARCH=arm64
export LIBRARY_PATH=/usr/lib/aarch64-linux-gnu:$LIBRARY_PATH
;;
esac

# Set paths based on OS
case "$os" in
Linux)
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
;;
Darwin)
export PATH=$PATH:/usr/local/bin
;;
FreeBSD)
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
;;
esac

# Configure based on kernel version
if [[ "$kernel" =~ ^[4-5]\. ]]; then
echo "Modern kernel detected ($kernel) - enabling modern features"
export MODERN_KERNEL=1
else
echo "Legacy kernel detected ($kernel) - using compatibility mode"
export MODERN_KERNEL=0
fi

# Create configuration file
cat > /tmp/system_config.sh << EOF
# System configuration generated on $(date)
export OS="$os"
export ARCH="$arch"
export KERNEL="$kernel"
export MODERN_KERNEL=$MODERN_KERNEL
export PATH="$PATH"
EOF

echo "System configuration complete"
source /tmp/system_config.sh
}

configure_based_on_system

System Compatibility Checker

#!/bin/bash
# Check system compatibility with requirements

check_compatibility() {
local min_kernel="$1"
local required_arch="$2"
local required_os="$3"

local current_kernel=$(uname -r)
local current_arch=$(uname -m)
local current_os=$(uname -s)

local compatible=true

echo "=== COMPATIBILITY CHECK ==="
echo "Required: Kernel >= $min_kernel, Architecture: $required_arch, OS: $required_os"
echo "Current: Kernel $current_kernel, Architecture: $current_arch, OS: $current_os"
echo ""

# Check kernel version
if [ "$(printf '%s\n' "$min_kernel" "$current_kernel" | sort -V | head -n1)" = "$min_kernel" ]; then
echo "❌ Kernel version check FAILED (minimum: $min_kernel, current: $current_kernel)"
compatible=false
else
echo "✅ Kernel version check PASSED"
fi

# Check architecture
case "$required_arch" in
x86_64)
if [[ "$current_arch" =~ ^(x86_64|i386|i686)$ ]]; then
echo "✅ Architecture check PASSED (compatible: $current_arch)"
else
echo "❌ Architecture check FAILED (required: x86_64, current: $current_arch)"
compatible=false
fi
;;
aarch64)
if [[ "$current_arch" =~ ^(aarch64|armv7l)$ ]]; then
echo "✅ Architecture check PASSED (compatible: $current_arch)"
else
echo "❌ Architecture check FAILED (required: aarch64, current: $current_arch)"
compatible=false
fi
;;
*)
if [ "$current_arch" = "$required_arch" ]; then
echo "✅ Architecture check PASSED"
else
echo "❌ Architecture check FAILED (required: $required_arch, current: $current_arch)"
compatible=false
fi
;;
esac

# Check operating system
if [ "$current_os" = "$required_os" ]; then
echo "✅ Operating system check PASSED"
else
case "$required_os" in
Linux)
if [[ "$current_os" =~ ^(Linux|GNU/Linux)$ ]]; then
echo "✅ Operating system check PASSED (compatible: $current_os)"
else
echo "❌ Operating system check FAILED (required: Linux, current: $current_os)"
compatible=false
fi
;;
*)
echo "❌ Operating system check FAILED (required: $required_os, current: $current_os)"
compatible=false
;;
esac
fi

echo ""
if [ "$compatible" = true ]; then
echo "✅ System is COMPATIBLE"
return 0
else
echo "❌ System is NOT COMPATIBLE"
return 1
fi
}

# Example usage
check_compatibility "4.15" "x86_64" "Linux"

System Information Fields Explained

Kernel Name (-s)

  • Linux - Standard Linux kernel
  • GNU/Linux - GNU/Linux system
  • Darwin - macOS kernel
  • FreeBSD - FreeBSD kernel
  • SunOS - Solaris kernel

Hostname (-n)

  • Returns the system's network hostname
  • Configured in /etc/hostname on modern Linux systems
  • Can be temporary or permanent based on configuration

Kernel Release (-r)

Format typically: VERSION.PATCHLEVEL-SUBLEVEL-EXTRA

  • 5.15.0 - Main kernel version 5.15.0
  • 52-generic - Ubuntu-specific patch level
  • 5.10.0-8-cloud - Cloud-specific kernel variant

Kernel Version (-v)

Contains build information:

  • #58 - Build number within series
  • SMP - Symmetric Multi-Processing support
  • Thu Oct 13 08:03:55 UTC 2022 - Build timestamp
  • gcc version - Compiler used for building

Machine Hardware (-m)

Common architectures:

  • x86_64 - 64-bit Intel/AMD
  • i386, i686 - 32-bit Intel/AMD
  • aarch64 - 64-bit ARM
  • armv7l - 32-bit ARM
  • ppc64le - 64-bit PowerPC (little-endian)

Processor Type (-p)

  • Often returns "unknown" on modern systems
  • Use /proc/cpuinfo for detailed CPU information
  • Historical option from older Unix systems

Hardware Platform (-i)

  • Often returns "unknown" on modern systems
  • Use dmidecode for detailed hardware information
  • Legacy option with limited modern use

Operating System (-o)

  • GNU/Linux - Most Linux distributions
  • Darwin - macOS
  • FreeBSD - FreeBSD
  • SunOS - Solaris

Platform-Specific Behavior

Linux Systems

# Linux-specific information gathering
get_linux_info() {
echo "=== Linux System Information ==="
uname -a
echo ""

# Distribution information
if [ -f /etc/os-release ]; then
echo "=== Distribution ==="
cat /etc/os-release | grep -E "^(PRETTY_|ID_|VERSION_)"
echo ""
fi

# Kernel modules
echo "=== Loaded Modules ==="
lsmod | head -10
echo ""

# System information
if [ -f /proc/version ]; then
echo "=== Kernel Build Information ==="
cat /proc/version
echo ""
fi
}

get_linux_info

macOS/Darwin Systems

# macOS-specific information gathering
get_macos_info() {
echo "=== macOS System Information ==="
uname -a
echo ""

# macOS version
echo "=== macOS Version ==="
sw_vers
echo ""

# System information
echo "=== System Information ==="
system_profiler SPSoftwareDataType | grep -E "(System Version|Kernel Version)"
echo ""

# Hardware information
echo "=== Hardware Information ==="
system_profiler SPHardwareDataType | grep -E "(Processor|Memory)"
echo ""
}

if [ "$(uname -s)" = "Darwin" ]; then
get_macos_info
fi

Troubleshooting

Common Issues and Solutions

Missing Information

# Some options may return "unknown"
uname -p # Often returns "unknown"
uname -i # Often returns "unknown"

# Use alternative commands for detailed information
if [ "$(uname -p)" = "unknown" ]; then
echo "Processor details:"
cat /proc/cpuinfo | grep "model name" | head -1
fi

if [ "$(uname -i)" = "unknown" ]; then
echo "Hardware platform:"
sudo dmidecode | grep "System Information" -A 5
fi

Hostname Issues

# Check hostname configuration
echo "Current hostname: $(uname -n)"
echo "Static hostname: $(cat /etc/hostname 2>/dev/null || echo 'not configured')"
echo "Transient hostname: $(hostnamectl status --transient 2>/dev/null || echo 'not available')"

# Fix hostname if needed
if [ -z "$(hostname)" ]; then
echo "Hostname is not set"
sudo hostname localhost
echo "Temporary hostname set to localhost"
fi

Cross-Platform Differences

# Handle different uname implementations
handle_uname_differences() {
local kernel=$(uname -s)

case "$kernel" in
Linux)
echo "Linux system detected"
# Linux-specific handling
;;
Darwin)
echo "macOS system detected"
# macOS-specific handling
;;
FreeBSD)
echo "FreeBSD system detected"
# FreeBSD-specific handling
;;
*)
echo "Unknown system: $kernel"
echo "uname output: $(uname -a)"
;;
esac
}

handle_uname_differences

Performance and Optimization

Efficient System Detection

# Cache uname results in long-running scripts
#!/bin/bash

# Cache system information to avoid repeated calls
SYSTEM_INFO_CACHE=""
get_cached_system_info() {
if [ -z "$SYSTEM_INFO_CACHE" ]; then
SYSTEM_INFO_CACHE=$(uname -a)
fi
echo "$SYSTEM_INFO_CACHE"
}

# Use cached information in loops
for i in {1..100}; do
sys_info=$(get_cached_system_info)
# Process using cached info
echo "Processing $i: $sys_info"
done

Minimal Resource Usage

# Use specific options instead of -a for minimal overhead
get_minimal_info() {
# Only get what's needed
local kernel_name=$(uname -s)
local architecture=$(uname -m)

# Use results without additional processing
echo "Kernel: $kernel_name, Arch: $architecture"
}

# Avoid parsing complex output
if [ "$(uname -m)" = "x86_64" ]; then
echo "64-bit system"
else
echo "32-bit system"
fi

Best Practices

Scripting Guidelines

  1. Use specific options (-m, -r) rather than parsing -a when possible
  2. Cache results in long-running scripts to avoid repeated system calls
  3. Combine with other tools for comprehensive system information
  4. Handle platform differences with conditional logic
  5. Validate input when using uname output for decision making

System Identification

  1. Use uname -a for complete system identification in bug reports
  2. Document system requirements using uname output format
  3. Create compatibility matrices for software deployment
  4. Monitor kernel versions for security updates and compatibility

Performance Considerations

  1. Minimize uname calls in performance-critical scripts
  2. Cache system information at script startup
  3. Use specific flags to reduce processing overhead
  4. Consider alternatives (/proc files) for real-time monitoring

The uname command is essential for system identification, compatibility checking, and platform-specific operations. While simple in appearance, it provides crucial information for system administration, software deployment, and cross-platform development, making it a fundamental tool in the Unix/Linux ecosystem.