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.
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.
df -h /System/Volumes/DataSize, used and available space on the volume that holds your files. Plain df -h / shows the read-only system volume, which looks almost empty.
diskutil info / | grep -i 'free space'The free space macOS reports for the whole disk container, in GB and bytes.
du -sh ~/Library/* 2>/dev/null | sort -h | tail -20The 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.
du -sh ~/* 2>/dev/null | sort -hEvery folder in your home folder by size, largest last.
du -sh ~/Library/Caches/* 2>/dev/null | sort -h | tail -10Which app's cache is biggest. Apps rebuild their caches, but quit the app before you delete its folder.
find ~ -type f -size +1G 2>/dev/nullEvery file over 1 GB in your home folder: old disk images, videos, virtual machine disks.
tmutil listlocalsnapshots /Time Machine's local snapshots on this disk. They count as purgeable space and macOS removes them when it needs the room.
lsof +L1Files 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.
memory_pressurePrints memory statistics and ends with “System-wide memory free percentage”. Low and falling means the Mac is short of memory.
sysctl vm.swapusageHow much swap is in use. Several GB of swap on a Mac that feels slow means it needs more memory than it has.
sysctl -n hw.memsize | awk '{print $1/1073741824 " GB"}'How much memory the Mac has, in GB.
top -l 1 -o mem -n 10 -stats pid,command,memThe 10 processes using the most memory right now.
vm_statRaw 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.
top -l 2 -o cpu -n 10 -stats pid,command,cpu | tail -11The 10 busiest processes. top needs two samples to measure CPU, so this takes two and shows the second.
uptimeHow long since the last restart, and the load average over 1, 5 and 15 minutes. Compare it with your number of CPU cores.
sysctl -n machdep.cpu.brand_stringThe chip, such as Apple M1 Pro.
sysctl hw.perflevel0.logicalcpu hw.perflevel1.logicalcpuHow many performance cores (perflevel0) and efficiency cores (perflevel1) the chip has.
pmset -g thermWhether macOS has recorded a thermal or performance warning, which means it has been slowing the CPU to keep it cool.
sudo powermetrics --samplers cpu_power -n 1CPU 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.
pmset -g battCharge, whether it's charging or on battery, and the time remaining.
system_profiler SPPowerDataType | grep -E 'Cycle Count|Condition|Maximum Capacity'Battery cycle count, condition and maximum capacity compared with new.
pmset -g assertionsEvery app and process currently stopping the Mac or its display from sleeping, and for how long.
pmset -g log | grep -E 'DarkWake|Wake from' | tail -20The last 20 wakes and dark wakes, each with its reason.
pmset -g schedWakes 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.
lsof -nP -iTCP -sTCP:LISTENEvery app listening for connections, with its process ID and port.
lsof -nP -iTCP:3000 -sTCP:LISTENWhat's using one port. Change 3000 to the port in your “address already in use” error.
nettop -P -L 1 -J bytes_in,bytes_outBytes received and sent by each process since it started, printed once.
networkQualityApple's built-in speed test: download and upload capacity and responsiveness.
ipconfig getifaddr en0Your 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.
pgrep -fl FinderEvery running process whose name or path contains the word, with its process ID. Replace Finder with any name.
ps -axo pid,rss,comm -m | head -15Processes sorted by memory, with resident size in KB.
kill 12345Asks 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.
launchctl list | grep -v com.appleBackground jobs loaded for your account that aren't Apple's.
ls ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemonsThe files that start helpers at login or at boot, by app.
sudo sfltool dumpbtmEverything 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.
sw_versThe macOS version and build number.
system_profiler SPHardwareDataTypeModel, chip, memory and serial number.
softwareupdate --listmacOS updates available, without installing any.
tmutil statusWhether a Time Machine backup is running: Running = 1 during a backup, Running = 0 when none is.
sudo tmutil latestbackupThe 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