CleanMate

All guides · macOS and Ubuntu · Updated

Find what is using disk space from the terminal on a Mac and on Ubuntu

Walk your disk from the terminal to the folder that fills it: df and diskutil for free space, du level by level with sort -h, ncdu to browse, the system folders a home-folder scan misses, why du and df disagree, and when a visual tool like Space Lens is quicker.

Download for macOS · Install on Ubuntu — free and open source

CleanMate Space Lens on a Mac, a chart of a home folder with its biggest folders listed by sizeCleanMate Space Lens on a Mac, a chart of a home folder with its biggest folders listed by size

The disk is almost full and you want the answer in a few commands, not a cleaning app. This guide walks the disk from the top down to the folder that holds the space, on macOS and Ubuntu, then explains the gaps a home-folder scan leaves and why the numbers of du and df rarely match. To list single big files instead (videos, disk images), see how to find large files on a Mac and on Ubuntu.

1. How much is free, and on which disk

Mac. Your files live on the Data volume of the startup disk, which shares one APFS container with the system:

df -h /System/Volumes/Data
diskutil info / | grep -E "Container (Total|Free) Space"

df and Disk Utility can show less free space than Finder: Finder adds space macOS can free by itself (purgeable), such as Time Machine local snapshots and iCloud files it can download again. See purgeable space and Time Machine snapshots.

Ubuntu.

df -h -x tmpfs -x squashfs      # real filesystems only, no snap images

If df shows space but programs still say the disk is full, the problem is not the size of a folder: see Ubuntu says the disk is full, but df shows free space.

2. Walk down with du

Start at your home folder, list each folder’s total, biggest last, then go into the biggest and repeat:

cd ~
du -xh -d 1 2>/dev/null | sort -h | tail -15
cd Library && du -xh -d 1 2>/dev/null | sort -h | tail -15     # then the next level

Three or four levels usually lead to the culprit. Typical answers on a Mac: ~/Library/Developer (Xcode), ~/Library/Application Support/MobileSync (iPhone backups), ~/Library/Caches and ~/Library/Logs (logs and crash reports), /opt/homebrew or /usr/local (Homebrew), media caches of video apps (Final Cut Pro and Adobe). On both systems: ~/Downloads (clean up Downloads), ~/.cache, and project folders full of node_modules.

3. Look outside your home folder

A scan of ~ misses what the system and other tools keep. Run du as root from the top, still with -x:

# Mac
sudo du -xh -d 1 /System/Volumes/Data 2>/dev/null | sort -h | tail
sudo du -xh -d 1 /System/Volumes/Data/private/var 2>/dev/null | sort -h | tail

# Ubuntu
sudo du -xh -d 1 / 2>/dev/null | sort -h | tail
sudo du -xh -d 1 /var 2>/dev/null | sort -h | tail

On a Mac, Terminal needs Full Disk Access to read Mail, Messages, Photos and other apps’ containers, even with sudo; without it those folders count as nearly empty. See Full Disk Access on macOS. /private/var/vm holds the sleep image and swap, and /private/var/folders holds per-user caches and temporary files.

On Ubuntu the usual suspects are /var/log and the journal, /var/lib/snapd, /var/lib/docker, /var/lib/flatpak and /var/cache/apt. Shrink each with the tool that owns it, never with rm: see the systemd journal, /var/log and the apt cache and Docker using too much disk space.

4. Browse with ncdu

ncdu does the walk for you: it scans once, then you move through the folders biggest first with the arrow keys.

sudo apt install ncdu        # Ubuntu
brew install ncdu            # Mac, with Homebrew
ncdu -x ~                    # your home folder, one disk
sudo ncdu -x /               # the whole system disk (Ubuntu)

On a server you can scan once and look later: ncdu -x -o /tmp/scan.json / writes the result, ncdu -f /tmp/scan.json opens it without scanning again. d in ncdu deletes for good, without the Trash.

On the Ubuntu desktop, Disk Usage Analyzer (baobab) is the graphical version: it scans a folder or the whole disk and draws a ring chart.

Why du and df disagree

When a visual tool is quicker

The terminal is best on a server, over SSH, or when you already suspect a folder. When you don’t know where to look, a tool that shows every folder at once, biggest first, and lets you click into it saves the five rounds of du. Deleting from such a tool can also go to the Trash, which rm and ncdu never do.

How CleanMate does it

CleanMate’s Space Lens is that visual view, on both systems (macOS features, Ubuntu features): More on it is on the Space Lens page.

The same engines run from the terminal, with --json for scripts: see the command line reference.

How Space Lens compares with DaisyDisk, GrandPerspective, Baobab and Filelight: the comparison.

FAQ

Why is du so slow on my home folder? It reads every file’s size. Narrow it to one folder, or use ncdu, which scans once and lets you browse the result.

Is sudo du safe? Yes, it only reads. Deleting outside your home folder is what can break the system: use the tool that owns the folder.

Why does du -sh * miss space? The * skips hidden files and folders. Use du -h -d 1 in the folder instead.

Skip the commands

CleanMate runs on both systems: pick yours.

Open source — star it on GitHub: CleanMate for macOS · CleanMate for Ubuntu

How CleanMate decides what is safe to remove →