Check Disk Usage
Displays disk usage for all physical drives with total, used, and free space in GB plus percentages. Filters out tmpfs and virtual filesystems.
Script
#!/bin/bash
printf "%-8s %12s %12s %12s %12s %12s\n" "Drive" "Total(GB)" "Used(GB)" "Free(GB)" "Used(%)" "Free(%)"
printf "%-8s %12s %12s %12s %12s %12s\n" "------" "---------" "--------" "--------" "-------" "-------"
df -B1 | awk '
NR>1 && $1 ~ /^\/dev\// {
if ($1 ~ /tmpfs|devtmpfs|overlay/) next
split($6, parts, "/")
drive = parts[length(parts)]
if (drive == "") drive = "/"
total = $2; used = $3; free = $4
total_gb = total / 1073741824
used_gb = used / 1073741824
free_gb = free / 1073741824
used_percent = (used / total) * 100
free_percent = (free / total) * 100
printf "%-8s %12.2f %12.2f %12.2f %12.2f %12.2f\n",
drive, total_gb, used_gb, free_gb, used_percent, free_percent
}' | sortLast updated on