Skip to main content

List of Linux exit status codes

Summary

List of standard and custom Linux exit status codes, numeric values ​​returned by commands or scripts that indicate success, failure, or specific error conditions. Using the correct code provides clarity, consistency, and aids in debugging and automation.

Introduction #

Linux exit status codes are numeric values returned by commands or scripts to indicate the outcome of their execution. A code of 0 signifies success, while non-zero codes represent errors or specific conditions.

Standard codes like 127 (command not found) and custom codes aid in debugging and automation, providing clarity about why a process failed or succeeded.

See the reference lists below to help you chose the correct exit status code for your scripts. Happy hacking.

List of Standard Exit Codes #

Exit CodeMeaning
0Success: The command or script executed without errors.
1General error: A generic error occurred during execution.
2Misuse of shell builtins: Incorrect usage of a shell built-in command.
126Command invoked cannot execute: Permission denied or command not executable.
127Command not found: The command is not recognized or available in the environment’s PATH.
128Invalid exit argument: An invalid argument was provided to the exit command.
130Script terminated by Ctrl+C (SIGINT).
137Script terminated by SIGKILL (e.g., kill -9 or out-of-memory killer).
139Segmentation fault: Indicates a segmentation fault occurred in the program.
143Script terminated by SIGTERM (e.g., kill command without -9).
255Exit status out of range: Typically, this happens when a script or command exits with a number > 255.

List of Custom Exit Codes #

The concept of custom exit codes is not universally defined — developers assign these in their scripts or programs based on the application’s needs.

However, there are some common conventions derived from software like sysexits.h (used in BSD systems) or informal practices across Unix and GNU/Linux. Below I have created an exhaustive list of widely-used custom exit codes along with their typical meanings:

Exit CodeMeaning
3Invalid argument: An incorrect or missing argument was provided to the script.
5Input/output error: Failure to read or write data.
6No such device or address: The specified device or address is unavailable.
64Command-line usage error: General syntax error in the command-line arguments.
65Data format error: The input data format is incorrect or unexpected.
66Cannot open input: A specified file or input cannot be accessed.
67Addressee unknown: Invalid or unknown destination address.
68Host name unknown: Unable to resolve the specified host.
69Service unavailable: A service required to complete the task is unavailable.
70Internal software error: An unhandled error occurred in the software or script logic.
71System error: Generic system-related error, such as insufficient resources.
72Critical OS file missing: Required system files are not accessible or missing.
73Cannot create: Failure to create a file or directory.
74I/O error: Generic input/output failure.
75Temporary failure: A temporary condition caused the failure (e.g., network issue).
76Remote protocol error: An error occurred in a remote communication protocol.
77Permission denied: The user or process lacks sufficient privileges.
78Configuration error: An issue occurred in configuration files or settings.

Why Use Exit Codes? #

Usage Tips #

Check Exit Codes #

After running a command, check its exit stautus code with:

echo $?

Handle Custom Codes in Scripts #

Use case statements to act on specific, custom exit codes:

my_command
case $? in
    0) echo "Success!";;
    1) echo "General error occurred.";;
    127) echo "Command not found.";;
    *) echo "Unhandled exit code.";;
esac

Define Exit Codes for Scripts #

In custom scripts, define meaningful exit codes to signal specific issues:

EX_USAGE=64
EX_FILE_NOT_FOUND=66
EX_SUCCESS=0

if [ ! -f "$1" ]; then
  echo "File not found!"
  exit $EX_FILE_NOT_FOUND
fi

Simplify Checks with && and || #

Use && to run a command only if the previous command succeeds and || to handle failures:

command && echo "Success" || echo "Failure"

Use exit to Stop Script Execution #

Exit immediately with a meaningful status if an error is detected:

if [ -z "$variable" ]; then
  echo "Error: Variable is unset!"
  exit 1
fi

Use trap for Cleanup on Error #

Ensure resources (e.g., temp files) are cleaned up, even if a script exits prematurely:

trap 'rm -f /tmp/myfile; exit' INT TERM EXIT
command || exit 1

Check Exit Status in Loops #

Handle failures within loops:

for file in *.txt; do
  process "$file"
  if [ $? -ne 0 ]; then
    echo "Error processing $file"
    exit 1
  fi
done

Avoid Confusion with Signal Numbers #

Exit codes >128 usually represent signals (128 + signal number), e.g., 130 means the script was terminated by SIGINT.

Combine set Options for Robust Scripts #

Enable stricter error handling with set options:


Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

License: List of Linux exit status codes by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/publications/linux-exit-status-codes">List of Linux exit status codes</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the DITig legal page.


“Form ever follows function.”

Louis Henry Sullivan, American architectThe Tall Office Building Artistically Considered, - IT quotes