Topic clusters
Mac Terminal commands for memory, swap, processes and disk
A reference of read-only commands, each tested on macOS 26. Every one works without installing anything, none changes your Mac, and each says what the output means.
These commands answer the questions people ask when a Mac gets slow or full: is memory short, which app holds it, what is listening on a port, and where did the disk space go. All of them only read information. None of them need an admin password. They were run on macOS 26 on Apple silicon; most behave the same on earlier versions.
One rule applies throughout: do not paste raw ps output with full command lines into public places. Command lines can contain passwords and API keys. The commands below avoid printing them.
Memory and swap
Start here. Memory pressure, not the amount of memory used, tells you whether a Mac is short.
sysctl -n kern.memorystatus_vm_pressure_level1 normal, 2 warning, 4 critical.
sysctl vm.swapusageused is memory macOS has written to disk. Growth over time is the sign of shortage.
memory_pressureEnds with System-wide memory free percentage. Higher is better. It also lists pages compressed and swapped.
vm_stat | grep -E "Swapins|Swapouts|Pageouts|compressor"Swap-ins climbing quickly while you work means the Mac keeps reading memory back from disk, which is what feels slow.
Biggest processes
ps reports resident memory (RSS): what is in RAM right now. It leaves out memory macOS has compressed or swapped out, and counts shared pages in every process that uses them, so it can read too low or too high. footprint reports what macOS actually charges to a process.
ps -axo rss=,etime=,comm= | sort -rn | head -10Memory in kilobytes, how long the process has run, and the program path.
footprint SafariMatches a process by name. The first column of the TOTAL row is dirty memory, including what is compressed or swapped. For an app made of many processes, pass several process IDs, for example footprint $(pgrep -f "/Applications/Cursor.app/").
top -l 1 -o mem -n 10 -stats pid,command,mem-l 1 prints one sample and exits, instead of refreshing.
Processes that outlive their app
A process whose parent has exited is reassigned to launchd, process ID 1. Long-running ones with parent 1 are the first place to look for leftovers.
ps -axo pid=,ppid=,rss=,etime=,comm= | awk '$2==1'Many are normal system services. Look for ones that belong to apps you have closed.
lsof -a -p 1234 -d cwd | tail -1Ports and dev servers
When a port is already in use, or a dev server will not die, find who is listening.
lsof -nP -iTCP -sTCP:LISTENThe first column is the program, the last is the address and port.
lsof -nP -iTCP:3000 -sTCP:LISTENDisk space
These find where space went without deleting anything.
df -h /du -d 1 -h ~ 2>/dev/null | sort -rh | head -10du -d 1 -h ~/Library 2>/dev/null | sort -rh | head -10tmutil listlocalsnapshots /Developer folders
The folders that grow quietly on a developer Mac. Run these in the folder that holds your projects.
find . -name node_modules -type d -prune -exec du -sh {} + | sort -rh | head -15-prune stops find from descending into each one, so it finishes quickly.
du -sh ~/Library/Developer/Xcode/DerivedDatadu -sh ~/.npmRun the whole check in one go
The free Mac memory check script runs the memory, swap, app and helper checks together and prints one readable report, without printing command lines.
Questions
How do I check memory pressure from Terminal?
Run sysctl -n kern.memorystatus_vm_pressure_level. It prints 1 for normal, 2 for warning and 4 for critical. memory_pressure prints a fuller summary.
How do I see swap usage on a Mac?
Run sysctl vm.swapusage. The used figure is the memory macOS has written to disk. Check it twice a few minutes apart: swap that keeps growing means the Mac is short of memory.
How do I see which process uses the most memory?
Run ps -axo rss=,etime=,comm= | sort -rn | head -10. For the figure macOS actually charges an app, including compressed memory, run footprint followed by the app name.
How do I find what is using a port on a Mac?
Run lsof -nP -iTCP:3000 -sTCP:LISTEN, replacing 3000 with the port. The first column is the program and the second is its process ID.
Are these commands safe to run?
Yes. Each one only reads information and none needs administrator rights. Commands that change anything are marked in their guides and ask you to check a path first.