How to Stop a Running Command in the Terminal with Ctrl+C in Bash and Zsh
Some commands don't end on their own: a web server, a log that keeps streaming, a script stuck waiting. Pressing Ctrl+C in the terminal asks the running command to stop, and gives you your prompt back. This guide stops a command in bash and in zsh and shows what it leaves behind.
Syntax
Ctrl+C
| Part | What it means |
|---|---|
| Ctrl+C | Hold Control and press C while a command is running in the foreground. On a Mac it's Control, not Command |
^C | How the terminal shows that you pressed it |
$? | Afterwards, the exit status of the stopped command |
Ctrl+C sends the running command a signal named SIGINT, interrupt. The zsh manual explains the number you see afterwards: "The value of a simple command is its exit status, or 128 plus the signal number if terminated by a signal."
The Example
sleep 60 waits a minute before it ends, which stands in for any long-running command. You stop it after two seconds and then print its exit status.
Step 1: Start a Command and Stop It
sleep 60
Press Ctrl+C while it's waiting. Then check how it ended:
echo "exit status: $?"
$ sleep 60
^C
$ echo "exit status: $?"
exit status: 130

zsh shows the same thing: ^C, then exit status: 130.
The terminal printed ^C where you pressed the keys, sleep stopped without waiting out its minute, and the prompt came back. The status 130 is 128 plus 2, and 2 is SIGINT's number: kill -l INT prints 2 in both shells.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Pressing Command+C on a Mac | That copies text. The command keeps running | Use the Control key |
| Closing the window to stop a server | The server may not get to stop cleanly | Press Ctrl+C first, and wait for the prompt |
| Pressing Ctrl+C with no command running | Nothing to stop: the shell just shows a fresh prompt | Only needed while something runs |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
^C appears but the prompt doesn't come back | The program is still finishing its shutdown, or ignores the signal | Wait a few seconds. If it stays stuck, stop it from another terminal |
| A later command reports exit status 130 | The previous command was stopped with Ctrl+C | Nothing to fix: that's what 130 means |
FAQ
Does Ctrl+C always stop a program?
It asks it to stop. Most programs stop at once. Some catch the signal to clean up first, such as servers that shut down their parts one by one, so they take a moment.
Conclusion
Ctrl+C stopped sleep 60 after two seconds, the terminal showed ^C, and $? was 130, which is 128 plus SIGINT's number 2. Use it to stop servers and stuck commands, and give them a moment to shut down.
Additional Resources
- zsh shell grammar — exit statuses of commands ended by a signal.
man 7 signalon Linux, orman signalon macOS — the list of signals.
