LinuxCommandLibrary

getconf

Get system configuration variables

TLDR

List [a]ll configuration values available

$ getconf -a
copy

List the configuration values for a specific directory
$ getconf -a [path/to/directory]
copy

Check if the system is 32-bit or 64-bit
$ getconf LONG_BIT
copy

Check how many processes the current user can run at once
$ getconf CHILD_MAX
copy

List every configuration value and then find patterns with the grep command (i.e every value with MAX in it)
$ getconf -a | grep MAX
copy

SYNOPSIS

getconf [-v version] { -a | name [pathname] ... }

PARAMETERS

-v version
    Query values for specific version (e.g., POSIX1_200112, POSIX_V7, XBS5_ILP32_OFF32).

-a
    Print all supported configuration names and values.

DESCRIPTION

getconf is a POSIX-compliant command that retrieves runtime values of system configuration variables, limits, and options. These include constants from <limits.h>, <unistd.h>, and filesystem-specific parameters. It uses underlying library calls like sysconf(), pathconf(), and confstr() to query the kernel or libc.

System-wide variables (prefixed _SC_) report machine characteristics, such as PAGESIZE or OPEN_MAX. Pathname arguments enable filesystem-specific queries like PATH_MAX or NAME_MAX for a directory. The -v option specifies conformance levels (e.g., POSIX_V7), useful for portable software detecting feature availability.

getconf -a dumps all supported variables, aiding system inspection. Values reflect dynamic configuration, differing from compile-time macros, ensuring adaptability across Linux, BSD, Solaris, and other Unix-like OS. Ideal for scripts adjusting to hardware/filesystem variances without assumptions.

CAVEATS

Returns "-1" if variable undetermined or unsupported. Pathname-required for file attributes; invalid paths fail. Values vary by kernel, libc, filesystem; not all POSIX vars implemented everywhere.

COMMON VARIABLES

PAGESIZE or _SC_PAGESIZE: Memory page size.
PATH_MAX: Max pathname length.
_SC_OPEN_MAX: Max open files per process.
_SC_CLK_TCK: Clock ticks/second.
NGROUPS_MAX: Max supplementary groups.

EXAMPLES

getconf PAGESIZE
4096
getconf -a | grep MAX
getconf NAME_MAX /tmp
255

HISTORY

Standardized in POSIX.1-2001 (Issue 6); earlier XPG4.2. Linux glibc support since ~2000; BSD/Solaris equivalents longstanding.

SEE ALSO

sysconf(3), pathconf(2), fpathconf(2), confstr(3), ulimit(1), uname(1)

Copied to clipboard