Git & Terminal Cheatsheet

Processes

Use this Git & Terminal reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Listing Processes

ps                  # processes started from this terminal
ps aux              # every process on the machine (detailed)
ps aux | grep node  # filter for a name (the grep itself may match too)
pgrep node          # just the PIDs matching a name
pgrep -fl "next dev"   # match the FULL command line, show it

Live Monitoring

top                 # built-in live process monitor (q quits)
top -o cpu          # macOS: sort by CPU
htop                # nicer interactive monitor (brew/apt install htop)
watch -n 2 "ps aux | grep node"   # re-run any command every 2 seconds

In top: q quits, k kills a PID. In htop: F6 sorts, F9 sends a signal, arrows select.

Stopping a Process

kill 12345              # send TERM: politely ask PID 12345 to stop
kill -9 12345           # send KILL: force-stop, no cleanup (last resort)
pkill node              # kill every process whose NAME matches
pkill -f "next dev"     # match against the full command line
killall node            # kill by exact process name
SignalNumberMeaning
TERM15graceful shutdown, the default, try this first
KILL9force kill, cannot be caught or ignored
INT2what ctrl+c sends
HUP1hang up, many daemons reload config on it
STOP / CONT19 / 18pause / resume without killing

Kill Whatever Is on a Port

The classic "port 3000 already in use" fix:

lsof -i :3000           # what is listening on port 3000 (name, PID, user)
lsof -ti :3000          # just the PID(s)
kill $(lsof -ti :3000)  # kill it
kill -9 $(lsof -ti :3000)   # force, if it ignores TERM
fuser -k 3000/tcp       # Linux one-liner alternative

Background Jobs

npm run dev &           # start a command in the background
jobs                    # list this shell's background jobs
fg                      # bring the most recent job to the foreground
fg %2                   # bring job number 2 forward
bg                      # resume a stopped job in the background
kill %1                 # kill job number 1

ctrl+z suspends the foreground process (state Stopped). Follow with bg to keep it running in the background or fg to resume it in front.

Keep It Running After You Log Out

A plain & job dies when the terminal closes. To survive logout:

nohup npm run build > build.log 2>&1 &   # immune to hangup, output to a file
disown %1                                # detach an already-running job
tmux                                     # or run it inside tmux/screen and detach

Quick Reference

TaskCommand
List everythingps aux
Find by namepgrep -fl <name>
Kill by PIDkill <pid> (then kill -9 if stuck)
Kill by namepkill -f <pattern>
Kill by portkill $(lsof -ti :<port>)
Live monitortop / htop
Background a jobcmd &, ctrl+z then bg
Survive logoutnohup cmd & or tmux