getconf
Get system configuration variables
TLDR
List [a]ll configuration values available
List the configuration values for a specific directory
Check if the system is 32-bit or 64-bit
Check how many processes the current user can run at once
List every configuration value and then find patterns with the grep command (i.e every value with MAX in it)
SYNOPSIS
getconf [-a] name [path]
PARAMETERS
-a
Displays all supported configuration variables and their current values. This option allows users to see a comprehensive list of what getconf can query on their system.
name
Specifies the name of the configuration variable to query. These names are typically uppercase and often prefixed with an underscore (e.g., _SC_PAGESIZE, ARG_MAX, _POSIX_VERSION). The output will be the value of this variable.
path
An optional pathname. When provided, getconf queries configuration variables that are specific to the file system on which the specified path resides. For example, variables like _POSIX_NO_TRUNC or NAME_MAX can vary per file system.
DESCRIPTION
The getconf command is a utility designed to retrieve and display the values of system configuration variables and limits. These variables typically conform to POSIX standards and provide crucial information about the operating environment, such as maximum file sizes, buffer sizes, process limits, and other system-wide or file-system-specific characteristics.
It serves as a command-line interface to the underlying sysconf(3) and pathconf(3) C library functions, making these system capabilities accessible for shell scripting and diagnostic purposes. Developers and system administrators use getconf to write portable scripts that adapt their behavior based on the system's capabilities and limitations, ensuring applications can function correctly across various Unix-like environments. For instance, one might query ARG_MAX to determine the maximum length of arguments to an exec family function, or _POSIX_VDISABLE to find the character used to disable special terminal characters.
CAVEATS
Variable names are case-sensitive and must exactly match the standard definitions. If a variable is not recognized or not defined on the system, getconf may output 'undefined' or an error.
Not all variables listed in POSIX standards are necessarily defined or have meaningful values on every system. Compliance varies across implementations.
Some non-standard options, like -v var (a GNU extension), might exist in certain implementations but should be avoided for portability.
Variables queried without a path argument are system-wide, while those with a path argument are specific to that file system. Understanding this distinction is crucial for correct usage.
TYPES OF CONFIGURATION VARIABLES
getconf can query two main types of configuration variables:
System-wide variables: These apply to the entire operating system, such as ARG_MAX (maximum length of arguments to a command), _POSIX_PAGESIZE (system page size), or LONG_BIT (number of bits in a long integer). These are queried by providing only the name argument.
Path-specific variables: These vary depending on the file system a given path resides on, such as NAME_MAX (maximum filename length in a directory), PATH_MAX (maximum pathname length), or _POSIX_NO_TRUNC (behavior for truncated filenames). These require both the name and path arguments.
PORTABILITY AND SCRIPTING
One of the primary uses of getconf is in writing portable shell scripts. By querying system limits rather than hardcoding values, scripts can adapt to different environments. For example, a script might check ARG_MAX before constructing a very long command line, or NAME_MAX before creating files with extremely long names, thus avoiding potential errors or unexpected behavior across various Unix-like systems.
HISTORY
getconf is an integral part of the POSIX.1 standard, providing a portable command-line interface to query system and path configuration values that are otherwise accessible through the sysconf() and pathconf() C library functions. Its development is closely tied to the evolution of the POSIX standard, which aims to ensure application portability across different Unix-like operating systems. It was introduced to give shell scripts and command-line users a standardized way to access system characteristics, mirroring the capabilities available to compiled programs. This allows for robust and adaptive scripting that can, for instance, determine maximum path lengths or argument sizes before attempting operations that might fail due to system limitations.