Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sysctl

Configure kernel parameters at runtime.

Description

Reads and writes kernel parameters exposed through the /proc/sys/ virtual filesystem. Parameters are identified by dotted key names (e.g., kernel.hostname), which map to files in the /proc/sys/ directory tree. Can also load settings in bulk from configuration files.

Inputs

  • /proc/sys/ – kernel parameter tree. Each parameter maps to a file: dots in key names become directory separators (e.g., kernel.hostname maps to /proc/sys/kernel/hostname). Slashes are also accepted as separators.
  • /etc/sysctl.conf – default configuration file (for -p)
  • /etc/sysctl.d/, /run/sysctl.d/, /usr/local/lib/sysctl.d/, /usr/lib/sysctl.d/, /lib/sysctl.d/ – system configuration directories (for --system)

Arguments

Positional

ArgumentDescription
variableKey to read (e.g., kernel.hostname). Prints the current value.
variable=valueKey=value pair to write. Sets the parameter to the given value.

Display options

FlagDescription
-n, --valuesPrint values only, without key names
-N, --namesPrint key names only, without values
-b, --binaryPrint value without a trailing newline

Read options

FlagDescription
-a, --allDisplay all available parameters (walks entire /proc/sys/ tree)
-r, --pattern REGEXOnly show keys matching the given extended regular expression

Write options

FlagDescription
-w, --writeForce all positional arguments to be treated as write operations
-q, --quietSuppress normal output when setting values

Load options

FlagDescription
-p, --load [FILE]Load settings from a file (default: /etc/sysctl.conf). Lines starting with # or ; are comments. Format: key = value.
--systemLoad settings from all system configuration directories and /etc/sysctl.conf

Error handling

FlagDescription
-e, --ignoreIgnore errors about unknown keys (silently skip them)

Behavior

Read mode

When given a variable argument without =, reads the corresponding file under /proc/sys/ and prints the result in key = value format. If the key path resolves to a directory rather than a file, recursively walks the directory showing all parameters beneath it.

Write mode

When given a variable=value argument (or any argument with -w), writes the value to the corresponding file under /proc/sys/. Requires appropriate permissions (usually root). Prints key = value confirming the change unless -q is specified.

List all (-a)

Recursively walks /proc/sys/ in sorted order, printing all readable parameters in key = value format. Parameters that are write-only or require elevated privileges to read are silently skipped.

Pattern filter (-r)

Filters output by matching the dotted key name against an extended regular expression. Can be combined with -a to filter the full parameter list or with individual reads to selectively display results.

Load mode (-p)

Reads a configuration file line by line and applies each setting:

  • Blank lines are skipped.
  • Lines starting with # or ; are treated as comments.
  • Each non-comment line should be in key = value format.
  • Whitespace around the = is trimmed.
  • Each setting is written to its corresponding /proc/sys/ path.

When invoked without a filename, defaults to /etc/sysctl.conf.

System load (--system)

Loads .conf files from the standard system configuration directories in the following order:

  1. /etc/sysctl.d/
  2. /run/sysctl.d/
  3. /usr/local/lib/sysctl.d/
  4. /usr/lib/sysctl.d/
  5. /lib/sysctl.d/

Within each directory, files are loaded in lexicographic order by filename. Finally, /etc/sysctl.conf is loaded. If the same key appears in multiple files, the last value wins.

Exit codes

CodeMeaning
0Success
1Failure (error reading or writing any parameter)