Exit the Terminal (Ctrl+D)
Press Ctrl+D to exit the shell or send end-of-input (EOF). On an empty command line it logs you out of the terminal session. Same key on macOS Terminal, Linux and Windows WSL / Git Bash.
| Action | Mac | Windows | |
|---|---|---|---|
| Exit shell / send EOF | Ctrl+D | Ctrl+D | |
| Stop running command | Ctrl+C | Ctrl+C | |
| Clear the screen | Ctrl+L | Ctrl+L | |
| Delete character under cursor | Ctrl+D | Ctrl+D |
Log out or end input
On an empty command line, Ctrl+D sends end-of-file (EOF) to the shell, which exits the session — the same as typing exit. It works the same in bash and zsh on macOS Terminal, Linux and Windows WSL / Git Bash.
Ctrl+D also means EOF inside programs
If a program is reading from standard input (for example cat with no file, or a Python prompt), Ctrl+D signals that input is finished. If the line already has text on it, Ctrl+D instead deletes the character under the cursor.
Ctrl+D vs exit vs logout
Ctrl+D and the exit command do the same thing for a normal shell. To stop Ctrl+D from accidentally closing your terminal, set IGNOREEOF in bash or setopt ignoreeof in zsh.
FAQ
How do I exit the terminal with the keyboard?
Press Ctrl+D on an empty line. It sends EOF to the shell and ends the session, the same as typing exit.
What does Ctrl+D do in the terminal?
On an empty line it logs out (EOF). Inside a program reading input it ends the input. With text on the line it deletes the character under the cursor.
How do I stop Ctrl+D from closing my terminal by accident?
In bash set the IGNOREEOF variable; in zsh run setopt ignoreeof. You will then need to press it several times or type exit.
Is Ctrl+D the same as Ctrl+C?
No. Ctrl+C interrupts a running command. Ctrl+D sends end-of-input and exits the shell or program.