Check Linux Limits and Features with getconf

Stop guessing how long a filename can be or how many arguments a command will take: getconf will tell you. You will finish with a small set of reliable checks for system limits, pathname limits and POSIX features. The examples use getconf from libc-bin version 2.39-0ubuntu8.9 on this machine.

Allow about ten minutes. You need a shell and the installed libc-bin package. These commands only read configuration exposed by the C library and kernel, so they need no sudo, edit no files and restart no services.

1. Confirm the command you are running

Locate the executable and check the package version first. That stops you diagnosing one host while running a different copy of the command:

$ command -v getconf
/usr/bin/getconf
$ dpkg-query -W -f='${Package} ${Version}\n' libc-bin
libc-bin 2.39-0ubuntu8.9

The package version is specific to this Debian-family installation and may change after an operating system update, so record it when a script or support report depends on exact behaviour. The interface here is the one documented in the installed getconf(1) man page.

Checkpoint: If command -v prints nothing, stop and install the package through your normal system-management process. Do not copy a binary from another host to make the examples work.

2. Query one system-wide value

Pass a system configuration variable as the only argument. ARG_MAX, for example, is the maximum combined size of arguments and environment data an exec operation can accept on this system:

$ getconf ARG_MAX
2097152

The output is a bare value, not a sentence and not a labelled measurement. Here it is 2,097,152 bytes. Keep the output numeric if a script will compare it. A limit is not necessarily a recommendation for normal application design.

Two more useful system-wide queries: the number of online processors, and the POSIX version the system advertises:

$ getconf _NPROCESSORS_ONLN
8
$ getconf POSIX2_VERSION
200809

Variable names are case-sensitive. Mistype one and getconf reports an unrecognised variable and exits unsuccessfully:

$ getconf DOES_NOT_EXIST
getconf: Unrecognized variable `DOES_NOT_EXIST'

Tip: Do not turn that error into a fallback value without deciding what the fallback means. A missing variable can point to a spelling error, an unsupported name or a portability difference.

3. Query a limit for a path

Pathname-specific variables come from pathconf(3) and need a pathname argument. Try PATH_MAX and NAME_MAX with a directory that exists and that you can access:

$ getconf PATH_MAX /tmp
4096
$ getconf NAME_MAX /tmp
255

For /tmp, PATH_MAX is 4096 and NAME_MAX is 255. The pathname is part of the question, not a placeholder. A mounted filesystem, network share or special filesystem can expose different limits, so query the directory where the operation will really happen.

Quote a pathname that comes from a variable or another command, so spaces and shell metacharacters stay inside one argument:

$ TARGET_DIR='/tmp'
$ getconf NAME_MAX "$TARGET_DIR"
255

Before you treat a failed query as a filesystem limit, confirm the path exists:

$ test -d "$TARGET_DIR" && echo 'directory is present'
directory is present

Checkpoint: You should see directory is present. If you do not, fix the path before you read anything into the query result.

4. List everything when exploring

Use -a to display all configuration variables and their values for the current system:

$ getconf -a
LINK_MAX                           65000
_POSIX_LINK_MAX                    65000
MAX_CANON                          255
MAX_INPUT                          255
PATH_MAX                           4096
ARG_MAX                            2097152
...

That is great for discovery and poor for scripts. The output is long, values can be blank, and the ordering and available names vary with the installed C library. Once you know what you need, switch to a named query such as getconf PATH_MAX /tmp.

When you capture the list, redirect it to a new file rather than overwriting an existing report:

$ getconf -a > getconf-$(hostname)-report.txt
$ test -s getconf-"$(hostname)"-report.txt && echo 'report is non-empty'
report is non-empty

Warning: Shell redirection creates or truncates the destination before getconf runs. The example uses a generated filename, but check it before you repeat the command in an important directory.

Recovery: If you create the report in the wrong place, remove that report only, after checking its exact path. Nothing else in this guide changes persistent system state.

5. Compare a named specification

The -v option asks for a variable under a named specification and version. This installed command accepts the POSIX profile name below and returns the width of a long integer:

$ getconf -v POSIX_V7_LP64_OFF64 LONG_BIT
64

This is a specification query. It does not change the process ABI or reconfigure the host: it tells you what value getconf can report for that specification. A number coming back does not make compiling with a different ABI safe.

Keep the specification and variable together in tests, and check the exit status when you need a result:

$ value=$(getconf -v POSIX_V7_LP64_OFF64 LONG_BIT) && test "$value" = 64
$ printf 'LP64 long width: %s bits\n' "$value"
LP64 long width: 64 bits

The command substitution keeps the value for comparison, and && stops the print step claiming success after a failed query. If another host does not accept the specification, treat that as a compatibility result and handle it explicitly.

6. Use results without over-trusting them

getconf reports interfaces exposed through sysconf(3), confstr(3) and pathconf(3). It does not inspect every application, filesystem operation or service configuration. A reported PATH_MAX does not prove an application builds paths safely, and _NPROCESSORS_ONLN does not promise a process can use every processor without contention.

For shell automation:

$ limit=$(getconf NAME_MAX /tmp) || {
>     printf 'could not query NAME_MAX for /tmp\n' >&2
>     exit 1
> }
$ case "$limit" in
>     ''|*[!0-9]*) printf 'unexpected limit: %s\n' "$limit" >&2; exit 1 ;;
> esac
$ printf 'NAME_MAX for /tmp: %s\n' "$limit"
NAME_MAX for /tmp: 255

This is ordinary, unprivileged shell work. It needs no service account, root shell or configuration file.

Tip: Avoid sudo getconf as a troubleshooting reflex. Elevated privileges do not make a misspelled variable valid, and they can make a pathname query answer for a different access context than your application has.

Done means