Windows exit equivalent in Linux
Closes the current shell session or exits a script, optionally with a numeric return code.
exit
exit
exit
exit
Overview
What this command does
On Windows, "exit" is used to exit the shell or return an exit code. On Linux, the closest practical mapping shown here is "exit". Closes the current shell session or exits a script, optionally with a numeric return code. This reference is grouped under Terminal & Shell Scripting → Terminal.
Windows → Linux context
What changes when you use this on Linux?
Same name, different environment
The basic command name exit is familiar on both platforms, but Linux path rules, quoting, permissions and available options can still change the result.
Portable across the compared distros
The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.
For the broader concept behind this mapping, read Linux command-line basics.
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
Debian/Ubuntu, Fedora and Arch all use "exit" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.
| 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