Skip to content

Instantly share code, notes, and snippets.

@barakacanbyte
Created March 30, 2026 18:38
Show Gist options
  • Select an option

  • Save barakacanbyte/6317aa21a16eccebf9b4a52415525011 to your computer and use it in GitHub Desktop.

Select an option

Save barakacanbyte/6317aa21a16eccebf9b4a52415525011 to your computer and use it in GitHub Desktop.
for cleaning up caches and junk

Here's the cleanup guide:


Ubuntu Disk Cleanup Guide

Safe to run anytime. Nothing here deletes personal files or system-critical data.


Step 1 — Check Disk Usage

df -h

Look at the Use% column for / (root). If it's above 85%, proceed.


Step 2 — Remove Unused APT Packages

sudo apt-get autoremove -y && sudo apt-get autoclean -y

Removes orphaned packages and old cached .deb files.


Step 3 — Remove Old Snap Revisions

Snap keeps old versions around unnecessarily.

# Limit snap to keep only 2 revisions going forward
sudo snap set system refresh.retain=2

# Remove all currently disabled (old) revisions
sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do
  sudo snap remove "$snapname" --revision="$revision"
done

⚠️ This only removes old versions — your current snap apps are unaffected.


Step 4 — Clear npm Cache

npm cache clean --force

Safe to clear anytime. npm rebuilds it as needed.


Step 5 — Empty the Trash

rm -rf ~/.local/share/Trash/*

Step 6 — Clear Developer Caches

These are all auto-regenerated by their tools:

rm -rf \
  ~/.cache/pnpm \
  ~/.cache/typescript \
  ~/.cache/gopls \
  ~/.cache/prisma \
  ~/.cache/ms-playwright-go \
  ~/.cache/node-gyp \
  ~/.cache/pip \
  ~/.cache/hardhat-nodejs \
  ~/.cache/staticcheck \
  ~/.cache/goimports \
  ~/.cache/thumbnails \
  ~/.cache/tracker3

⚠️ Skip any entries that don't apply to your stack. All are safe to delete.


Step 7 — Trim System Journal Logs

Keeps only logs from the last 7 days:

sudo journalctl --vacuum-time=7d

Step 8 — Verify Results

df -h /

Compare Avail before and after.


Investigation Commands (Run First if Unsure)

Find what's eating space before deleting anything:

# Top-level home directory sizes
du -sh ~/* 2>/dev/null | sort -rh | head -20

# Snap data breakdown
du -sh ~/snap/*/ 2>/dev/null | sort -rh

# Cache breakdown
du -sh ~/.cache/* 2>/dev/null | sort -rh | head -15

# Downloads folder
du -sh ~/Downloads/* 2>/dev/null | sort -rh | head -20

What to Review Manually

These require human judgment — do not auto-delete:

Path Typical Size Action
~/Downloads/ Varies Delete files you no longer need
~/snap/firefox/ 2–4 GB Keep unless switching to deb/flatpak
~/snap/discord/ 1–2 GB Keep unless unused
~/.npm/ 2–6 GB Safe to clear (Step 4 above)

Expected Space Recovery

Step Typical Savings
APT cleanup 100–500 MB
Old snap revisions 500 MB – 3 GB
npm cache 2–6 GB
Trash Varies
Dev caches 500 MB – 2 GB
Journal logs 200–500 MB
Total ~4–12 GB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment