---
title: "Mac Terminal commands for memory, swap, disk · MacMelon"
description: "Tested, read-only macOS commands to check memory pressure, swap, the biggest processes, listening ports and disk space, with what each output means."
url: "https://macmelon.com/guides/mac-terminal-commands-memory-swap-disk"
---

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

By [Harish Ganapathi](https://macmelon.com/about), Co-founder · Updated November 13, 2026

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.

-   [Memory pressure](https://macmelon.com/glossary/memory-pressure)
-   [Swap](https://macmelon.com/glossary/swap-memory)
-   [Compressed memory](https://macmelon.com/glossary/compressed-memory)

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

-   [Memory footprint](https://macmelon.com/glossary/memory-footprint)

## 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
```

-   [Find and stop leftover MCP servers](https://macmelon.com/guides/claude-code-mcp-servers-still-running-on-mac)

## 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 /
```

-   [Why System Data is so large](https://macmelon.com/guides/why-is-mac-system-data-so-large)

## 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
```

-   [Clear Xcode DerivedData safely](https://macmelon.com/guides/how-to-clear-xcode-deriveddata-safely)
-   [Delete node\_modules safely](https://macmelon.com/use-cases/delete-node-modules-safely)

## Run the whole check in one go

The [free Mac memory check script](https://macmelon.com/guides/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.

## Related use cases

[### Find out why your Mac is slow](https://macmelon.com/use-cases/find-out-why-your-mac-is-slow)[### Free up space on a MacBook](https://macmelon.com/use-cases/free-up-space-on-a-macbook)[### Delete node\_modules safely](https://macmelon.com/use-cases/delete-node-modules-safely)

## Related terms

[### Memory pressure](https://macmelon.com/glossary/memory-pressure)[### Swap](https://macmelon.com/glossary/swap-memory)[### Memory footprint](https://macmelon.com/glossary/memory-footprint)[### System Data](https://macmelon.com/glossary/system-data)[### node\_modules](https://macmelon.com/glossary/node-modules)

## Related notes

[### Developer Mac memory after two days: measured](https://macmelon.com/blog/developer-mac-memory-snapshot-november-2026)
