Windows
Linux
Terminal & Shell Scripting
Terminal
Windows exit equivalent in Linux
Closes the current shell session or exits a script, optionally with a numeric return code.
Windows
→
exit
Linux equivalents
exit
exit
exit
Overview
What this command does
Closes the current shell session or exits a script, optionally with a numeric return code.
Migration tip: Exit codes matter in Linux. 0 = success, anything else = failure. Use
$? to check the exit code of the last command. Scripts should always exit with a meaningful code.Practical tasks
Common use cases
Exit the shell or return an exit code
Closes the current shell session or exits a script, optionally with a numeric return code.
exit
Exit with code 0 (success)
exit 0
Explicit success
exit 1
Exit with error code
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
exit
exit 0
exit 1
ls /tmp
echo $?
set -euo pipefail
Walkthrough
Examples with explanations
# Windows: exit 0
exit # close terminal / end script
exit 0 # success
exit 1 # failure
# Check if last command succeeded:
ls /tmp
echo $? # 0 = success
# Error-safe script header:
#!/bin/bash
set -euo pipefail
Reference
Common options and variations
| Command or option | Use |
|---|---|
exit | Exit with code 0 (success) |
exit 0 | Explicit success |
exit 1 | Exit with error code |
echo $? | Check exit code of last command |
set -e | Exit script automatically on any error |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | exit |
Same command on this distribution. |
| Fedora | same command | exit |
Same command on this distribution. |
| Arch | same command | exit |
Same command on this distribution. |
Keep learning