DEV Community

Ben Santora
Ben Santora

Posted on

Linux Disk Analysis Script

This simple bash script gives you three views of your Linux system.
1 - a high-level disk summary
2 - a list of the largest directories in your home folder
3 - a list of the largest individual files
Everything is read-only and safe to run - nothing is deleted.

#!/bin/bash

# Color definitions
CYAN='\033[1;36m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'  # No Color

echo -e "${CYAN}${BOLD}=== DISK USAGE OVERVIEW ===${NC}"
echo

# Show overall disk usage in a human-readable format
df -h | awk 'NR==1 || /^\/dev/'

echo
echo -e "${CYAN}${BOLD}=== TOP DIRECTORIES IN YOUR HOME FOLDER ===${NC}"
echo

# Check that HOME is set
if [ -z "$HOME" ]; then
    echo -e "${RED}HOME directory not set. Cannot continue.${NC}"
    exit 1
fi

# Show the largest directories in the home folder
du -sh "$HOME"/* 2>/dev/null | sort -h | tail -n 10

echo
echo -e "${CYAN}${BOLD}=== LARGEST FILES IN YOUR HOME FOLDER ===${NC}"
echo

# Find large files without crossing filesystem boundaries
find "$HOME" -xdev -type f -exec du -h {} + 2>/dev/null | sort -h | tail -n 10

echo
echo -e "${GREEN}${BOLD}Analysis complete.${NC}"
Enter fullscreen mode Exit fullscreen mode

Bash Scripting Series - Ben Santora - January 2026

Top comments (0)