YBee24 / Yasmina-and-Lucien-Shell-Problem-Project-Friday-26-July

0 stars 0 forks source link

create disk usage function #8

Open Luciensday opened 3 months ago

YBee24 commented 3 months ago

!/bin/bash

Function to check disk usage

check_disk_usage() { echo "Disk Usage Information:"

# Get disk usage info using df command
df -h --total | awk '
BEGIN {
    printf "%-20s %-10s %-10s %-10s %-10s %-10s\n", "Filesystem", "Size", "Used", "Avail", "Use%", "Mounted on"
}
NR>1 {
    printf "%-20s %-10s %-10s %-10s %-10s %-10s\n", $1, $2, $3, $4, $5, $6
}
'

echo ""
echo "Summary (Total):"

# Display the total disk usage across all filesystems
df -h --total | awk '
END {
    printf "Total Size: %-10s\n", $2
    printf "Total Used: %-10s\n", $3
    printf "Total Available: %-10s\n", $4
    printf "Total Usage: %-10s\n", $5
}
'

}

Call the function

check_disk_usage