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.

Memory pressure level
sysctl -n kern.memorystatus_vm_pressure_level

1 normal, 2 warning, 4 critical.

Swap in use
sysctl vm.swapusage

used is memory macOS has written to disk. Growth over time is the sign of shortage.

A readable memory summary
memory_pressure

Ends with System-wide memory free percentage. Higher is better. It also lists pages compressed and swapped.

Raw counters, including swap-ins and swap-outs since boot
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.

Ten largest processes, name only
ps -axo rss=,etime=,comm= | sort -rn | head -10

Memory in kilobytes, how long the process has run, and the program path.

Memory macOS charges to a process (replace Safari)
footprint Safari

Matches 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/").

Apps and processes at the top of memory, once
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.

Processes with no parent, with memory and age
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.

Which folder a process was started in (replace 1234)
lsof -a -p 1234 -d cwd | tail -1

Ports and dev servers

When a port is already in use, or a dev server will not die, find who is listening.

Everything listening on a TCP port
lsof -nP -iTCP -sTCP:LISTEN

The first column is the program, the last is the address and port.

Who is using one port (replace 3000)
lsof -nP -iTCP:3000 -sTCP:LISTEN

Disk space

These find where space went without deleting anything.

Free space on the startup disk
df -h /
Largest folders in your home folder
du -d 1 -h ~ 2>/dev/null | sort -rh | head -10
Largest folders in your Library
du -d 1 -h ~/Library 2>/dev/null | sort -rh | head -10
List local Time Machine snapshots
tmutil listlocalsnapshots /

Developer folders

The folders that grow quietly on a developer Mac. Run these in the folder that holds your projects.

Every node_modules folder under the current folder, largest first
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.

Xcode DerivedData size
du -sh ~/Library/Developer/Xcode/DerivedData
npm's download cache size
du -sh ~/.npm

Run 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.