Back to commands

Apple Terminal

Read-only, can be slow

Find What Is Using a Local Dev Port

A local server will not start because another process is already listening on the same TCP port.

Command

lsof -nP -iTCP:3000 -sTCP:LISTEN

Before you run this

System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.

When not to use it: Do not use it to inspect remote servers. It only checks the local Mac.

Expected output

A row showing the command name, PID, user, and LISTEN socket for port 3000.

System impact

Read-only, can be slow. Nothing changes. The command reports the process listening on the port.

Scope this to the smallest useful path or service on busy systems.

Recovery / rollback: no state is changed.

When to use it

Use when Vite, Next.js, Rails, Django, or another local server refuses to bind to a port.

When not to use it

Do not use it to inspect remote servers. It only checks the local Mac.

Explanation-only example

Illustrated output, not a live lab run

This example is intentionally illustrative. It shows the command shape without killing real processes or changing your machine.

demo@lab:~$

$ printf '%s\n' 'COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME' 'node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)'

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)

$ printf '%s\n' 'COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME' 'node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)' | awk 'NR==1 || /LISTEN/'

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. printf '%s\n' 'COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME' 'node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)'
  2. printf '%s\n' 'COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME' 'node 4242 uri 23u IPv6 0xabc 0t0 TCP *:3000 (LISTEN)' | awk 'NR==1 || /LISTEN/'

next steps

Related commands

Apple Terminal Stops processes

Flush macOS DNS Cache

Changed DNS but your Mac still visits the old place? Flush the resolver cache.

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:109-networking
  • lfcs:networking
  • linuxplus:provisional
  • linuxplus:troubleshooting
  • risk:macos-only
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.