Skip to content
Black FridayBlack Friday: both apps $5.99, ends 1 Dec

Terminal reference

Mac Terminal commands to check your Mac

40 commands for disk space, memory, CPU, battery, network and startup items. Each one only looks, except kill, which says so. Copy, paste into Terminal, read the answer.

Updated · Run on macOS 27 on Apple silicon; commands marked sudo checked against their manual pages.

Open Terminal from Applications → Utilities, or press Command-Space and type Terminal. Commands marked sudo ask for your Mac password; nothing appears while you type it.

Disk space

Find what's filling the disk. du only reads sizes; nothing here deletes anything.

Terminal
df -h /System/Volumes/Data

Size, used and available space on the volume that holds your files. Plain df -h / shows the read-only system volume, which looks almost empty.

Terminal
diskutil info / | grep -i 'free space'

The free space macOS reports for the whole disk container, in GB and bytes.

Terminal
du -sh ~/Library/* 2>/dev/null | sort -h | tail -20

The 20 biggest folders in your Library, largest last. Caches, Application Support and Developer are the usual suspects. 2>/dev/null hides the folders macOS won't let Terminal read.

Terminal
du -sh ~/* 2>/dev/null | sort -h

Every folder in your home folder by size, largest last.

Terminal
du -sh ~/Library/Caches/* 2>/dev/null | sort -h | tail -10

Which app's cache is biggest. Apps rebuild their caches, but quit the app before you delete its folder.

Terminal
find ~ -type f -size +1G 2>/dev/null

Every file over 1 GB in your home folder: old disk images, videos, virtual machine disks.

Terminal
tmutil listlocalsnapshots /

Time Machine's local snapshots on this disk. They count as purgeable space and macOS removes them when it needs the room.

Terminal
lsof +L1

Files that were deleted but are still held open by an app. Their space comes back only when that app quits.

More: What's taking up space on my Mac? · Purgeable space explained

Memory and swap

How much memory is in use, how much is swapped to disk, and which processes hold the most.

Terminal
memory_pressure

Prints memory statistics and ends with “System-wide memory free percentage”. Low and falling means the Mac is short of memory.

Terminal
sysctl vm.swapusage

How much swap is in use. Several GB of swap on a Mac that feels slow means it needs more memory than it has.

Terminal
sysctl -n hw.memsize | awk '{print $1/1073741824 " GB"}'

How much memory the Mac has, in GB.

Terminal
top -l 1 -o mem -n 10 -stats pid,command,mem

The 10 processes using the most memory right now.

Terminal
vm_stat

Raw page counts: free, active, wired, compressed. Multiply by the page size on the first line (16384 bytes on Apple silicon) to get bytes.

More: What is memory pressure? · Swap in the glossary · Wired memory in the glossary

CPU and heat

What's using the processor, how busy it has been, and whether the Mac is slowing itself down to stay cool.

Terminal
top -l 2 -o cpu -n 10 -stats pid,command,cpu | tail -11

The 10 busiest processes. top needs two samples to measure CPU, so this takes two and shows the second.

Terminal
uptime

How long since the last restart, and the load average over 1, 5 and 15 minutes. Compare it with your number of CPU cores.

Terminal
sysctl -n machdep.cpu.brand_string

The chip, such as Apple M1 Pro.

Terminal
sysctl hw.perflevel0.logicalcpu hw.perflevel1.logicalcpu

How many performance cores (perflevel0) and efficiency cores (perflevel1) the chip has.

Terminal
pmset -g therm

Whether macOS has recorded a thermal or performance warning, which means it has been slowing the CPU to keep it cool.

Terminal · needs sudo
sudo powermetrics --samplers cpu_power -n 1

CPU and GPU power use and how busy each cluster of cores is, measured once.

More: CPU load average in the glossary · Performance and efficiency cores · Why kernel_task uses so much CPU

Battery and sleep

Battery health, what's keeping the Mac awake, and what woke it up overnight.

Terminal
pmset -g batt

Charge, whether it's charging or on battery, and the time remaining.

Terminal
system_profiler SPPowerDataType | grep -E 'Cycle Count|Condition|Maximum Capacity'

Battery cycle count, condition and maximum capacity compared with new.

Terminal
pmset -g assertions

Every app and process currently stopping the Mac or its display from sleeping, and for how long.

Terminal
pmset -g log | grep -E 'DarkWake|Wake from' | tail -20

The last 20 wakes and dark wakes, each with its reason.

Terminal
pmset -g sched

Wakes macOS has scheduled for later, and what asked for each one.

More: Why does my Mac keep waking up? · Battery drain overnight · Sleep assertions in the glossary

Network and ports

What's listening on your Mac, which apps use the network, and how fast the connection is.

Terminal
lsof -nP -iTCP -sTCP:LISTEN

Every app listening for connections, with its process ID and port.

Terminal
lsof -nP -iTCP:3000 -sTCP:LISTEN

What's using one port. Change 3000 to the port in your “address already in use” error.

Terminal
nettop -P -L 1 -J bytes_in,bytes_out

Bytes received and sent by each process since it started, printed once.

Terminal
networkQuality

Apple's built-in speed test: download and upload capacity and responsiveness.

Terminal
ipconfig getifaddr en0

Your Mac's local IP address on Wi-Fi (on most Macs, en0 is Wi-Fi).

More: Port 5000 or 3000 already in use · Find and stop leftover dev servers · Listening port in the glossary

Processes and startup items

Find a process, stop one that's stuck, and see what starts when you log in.

Terminal
pgrep -fl Finder

Every running process whose name or path contains the word, with its process ID. Replace Finder with any name.

Terminal
ps -axo pid,rss,comm -m | head -15

Processes sorted by memory, with resident size in KB.

Terminal · changes something
kill 12345

Asks process 12345 to quit, the same as quitting it normally. Use the ID from pgrep or lsof. Only if it ignores that, kill -9 12345 stops it at once, without saving.

Terminal
launchctl list | grep -v com.apple

Background jobs loaded for your account that aren't Apple's.

Terminal
ls ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons

The files that start helpers at login or at boot, by app.

Terminal · needs sudo
sudo sfltool dumpbtm

Everything registered as a login item or background item, including items you switched off in System Settings.

More: What is this Mac process? Look up any name · Background items added: what to check · launchd in the glossary

System and backups

Which Mac and macOS version this is, and whether Time Machine is keeping up.

Terminal
sw_vers

The macOS version and build number.

Terminal
system_profiler SPHardwareDataType

Model, chip, memory and serial number.

Terminal
softwareupdate --list

macOS updates available, without installing any.

Terminal
tmutil status

Whether a Time Machine backup is running: Running = 1 during a backup, Running = 0 when none is.

Terminal · needs sudo
sudo tmutil latestbackup

The newest finished Time Machine backup, named with its date and time. The backup disk must be connected.

More: Is Time Machine backing up? · Mac slow after a macOS update

Rather not run commands every time?

iKnowMyMac watches the same things from the menu bar: memory and swap, what’s keeping the Mac awake, what woke it, listening ports, disk space and the last Time Machine backup, and keeps the history so you can see what changed. See pricing →

FAQ

Terminal command questions

Something else? support@iknowmymac.com

How do I see what's taking up space on my Mac in Terminal?

Run du -sh ~/Library/* 2>/dev/null | sort -h | tail -20 to list the biggest folders in your Library, largest last, then du -sh ~/* 2>/dev/null | sort -h for your home folder. df -h /System/Volumes/Data shows how much space is free.

How do I check memory use on a Mac from Terminal?

memory_pressure ends with the free percentage, sysctl vm.swapusage shows how much is swapped to disk, and top -l 1 -o mem -n 10 -stats pid,command,mem lists the 10 processes using the most memory.

How do I find what's using a port on a Mac?

Run lsof -nP -iTCP:3000 -sTCP:LISTEN, with your port in place of 3000. It shows the app and its process ID. kill followed by that ID asks it to quit.

Are these commands safe to run?

All of them only read information, except kill, which stops a process. Commands that start with sudo ask for your administrator password because they read system data. None of them deletes files.

Know why your Mac is slow.

macOS 15 Sequoia or later · Apple silicon. A 56.9 MB native app, notarized by Apple. No account, no analytics, no telemetry.

One-time purchase · every feature · 5-day refund