Building a Simple System Information Script in Bash
Ever needed a quick way to check your system’s vital stats without memorizing a dozen different commands?
I created a simple bash script that displays all the essential system information in one clean output.
What It Does
The script displays:
Hostname and current date
System uptime
Linux distribution and kernel version
CPU model and core count
Memory usage (total, used, free)
Disk space utilization
Network information (IPv4, MAC address, gateway, DNS)
The Script
Here’s the complete script:
#!/bin/bash
# Description: Display system informationecho"=== System Info ==="echo"Hostname: $(hostname)"echo"Date: $(date)"echo"Uptime: $(uptime -p | sed 's/up //')"echo"Distro: $(lsb_release -ds 2>/dev/null || grep PRETTY_NAME /etc/os-release | cut -d'"' -f2)"echo"Kernel: $(uname -r)"# CPU informationecho"CPU: $(lscpu | grep 'Model name'| cut -d':' -f2 | xargs)"# Memory informationecho"Mem: $(free -h | awk '/^Mem:/ {print $2 " total, " $3 " used, " $4 " free"}')"# Disk informationecho"Disk: $(df -h / | awk 'NR==2 {print $2 " total, " $3 " used, " $4 " free (" $5 " used)"}')"# IP address (primary interface)echo"IPv4: $(hostname -I | awk '{print $1}')"# MAC address (primary interface)echo"MAC: $(ip link show | awk '/ether/ {print $2; exit}')"# Default Gatewayecho"Gateway: $(ip route | grep default | awk '{print $3}')"# DNS Server (current)echo"DNS: $(resolvectl status | grep 'Current DNS Server:'| awk '{print $4}')"