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.hostnamemaps 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
| Argument | Description |
|---|---|
variable | Key to read (e.g., kernel.hostname). Prints the current value. |
variable=value | Key=value pair to write. Sets the parameter to the given value. |
Display options
| Flag | Description |
|---|---|
-n, --values | Print values only, without key names |
-N, --names | Print key names only, without values |
-b, --binary | Print value without a trailing newline |
Read options
| Flag | Description |
|---|---|
-a, --all | Display all available parameters (walks entire /proc/sys/ tree) |
-r, --pattern REGEX | Only show keys matching the given extended regular expression |
Write options
| Flag | Description |
|---|---|
-w, --write | Force all positional arguments to be treated as write operations |
-q, --quiet | Suppress normal output when setting values |
Load options
| Flag | Description |
|---|---|
-p, --load [FILE] | Load settings from a file (default: /etc/sysctl.conf). Lines starting with # or ; are comments. Format: key = value. |
--system | Load settings from all system configuration directories and /etc/sysctl.conf |
Error handling
| Flag | Description |
|---|---|
-e, --ignore | Ignore 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 = valueformat. - 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:
/etc/sysctl.d//run/sysctl.d//usr/local/lib/sysctl.d//usr/lib/sysctl.d//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
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Failure (error reading or writing any parameter) |