A simple Bash script to scan and identify disk bloat in WSL2 (Windows Subsystem for Linux) environments.
- Scans top 15 largest directories in
$HOME. - Reports sizes of common tool caches (Docker, Mise, UV, Playwright, NPM, etc.).
- Identifies potential junk files like Java heap dumps (
.hprof) and large installer files (.run). - Provides one-touch cleanup commands.
# Download and make executable
curl -L https://gist.githubusercontent.com/InTEGr8or/YOUR_GIST_ID/raw/wsl-cleanup.sh -o wsl-cleanup.sh
chmod +x wsl-cleanup.sh
# Recommended: Add an alias to your .bashrc
alias wsl-cleanup='~/wsl-cleanup.sh'Run the scan:
./wsl-cleanup.shRun basic auto-cleanup (Docker, Mise, UV, and .hprof files):
./wsl-cleanup.sh --autoAfter cleaning files inside WSL, you must compact the virtual disk to see the space return to your Windows drive. Run this from Windows PowerShell (Admin):
wsl --shutdown
optimize-vhd -Path "C:\Users\<YourUser>\AppData\Local\Packages\<DistroPackage>\LocalState\ext4.vhdx" -Mode Full