LinuxCommandLibrary

errno

Display the last system call error number

TLDR

Lookup errno description by name or code

$ errno [name|code]
copy

List all errno names, codes, and descriptions
$ errno [[-l|--list]]
copy

Search for code whose description contains all of the given text
$ errno [[-s|--search]] [text]
copy

Search for code whose description contains all of the given text (all locales)
$ errno [[-S|--search-all-locales]] [text]
copy

SYNOPSIS

errno [OPTIONS] [NUMBER|NAME...]

Examples:
errno
errno 13
errno EPERM
errno 2 ENOENT

PARAMETERS

-l, --list
    Lists all known error codes, their symbolic names, and descriptions.

-s, --string
    Displays only the descriptive error string for the given input(s).

-n, --name
    Displays only the symbolic error name (e.g., ENOENT) for the given input(s).

-v, --value
    Displays only the numeric value of the error code for the given input(s).

-h, --help
    Shows a help message and exits.

-V, --version
    Displays version information and exits.

DESCRIPTION

The `errno` command is a utility designed to help programmers and system administrators understand system error codes.

When a C program's system call fails, the global variable `errno` (defined in ``) is set to a specific integer value indicating the reason for the failure. However, these numeric values are often not immediately intuitive. The `errno` command allows users to translate these numeric error codes into their human-readable symbolic names (e.g., `1` to `EPERM`) and descriptive strings (e.g., "Operation not permitted").

Conversely, it can also translate symbolic error names (like `ENOENT`) back into their numeric equivalents. This functionality is invaluable for debugging C/C++ applications, interpreting logs that contain raw error numbers, and generally gaining a clearer understanding of why certain system operations might fail. It acts as a convenient lookup tool for the error codes defined by the operating system.

CAVEATS

The specific set of error codes and their exact descriptions can vary slightly between different Unix-like operating systems (e.g., Linux, FreeBSD, macOS). This utility relies on the system's `strerror(3)` implementation and definitions in ``. It is primarily a convenience tool and may not be installed by default on all Linux distributions, often being part of developer tools or specific packages like `error.h` or `libbsd`.

<I>THE C STANDARD LIBRARY AND ERRNO.H</I>

The primary context for `errno` is within C/C++ programming. The `` header file defines macros for various error codes (e.g., `EACCES`, `ENOENT`, `EAGAIN`). When a system call fails, it typically returns `-1` and sets the global integer variable `errno` to indicate the specific error. The `errno` command-line tool provides a user-friendly way to query these definitions without consulting C headers or man pages directly.

HISTORY

While the concept of `errno` (the global variable and `` definitions) has been fundamental to Unix-like systems since their inception, the `errno` command-line utility is a more recent development. It emerged as a helpful debugging aid, often provided by specific packages (like `error.h` on Debian/Ubuntu-based systems or `libbsd` on others) rather than being part of core GNU utilities. Its purpose is to provide an easily accessible lookup for information traditionally found in programming manual pages, streamlining the development and debugging workflow for C/C++ programmers.

SEE ALSO

strerror(3), perror(3), errno(3), intro(2)

Copied to clipboard