Linux dmesg command

Updated: 03/13/2021 by Computer Hope
dmesg command

On Linux operating systems, the dmesg command examines or controls the kernel ring buffer.

The kernel ring buffer is a data structure that records messages related to the operation of the kernel. A ring buffer is a special kind of buffer that is always a constant size, removing the oldest messages when new messages are received.

Syntax

dmesg [options]

Options

-C, --clear Clear the ring buffer.
-c, --read-clear Clear the ring buffer contents after printing.
-D, --console-off Disable printing messages to the console.
-d, --show-delta Display the timestamp and time delta spent between messages. If used with --notime, then only the time delta without the timestamp is printed.
-E, --console-on Enable printing messages to the console.
-f, --facility list Restrict output to defined (comma separated) list of facilities. For all supported facilities see --help output.
-h, --help Print a help text and exit.
-k, --kernel Print kernel messages.
-l, --level list Restrict output to defined (comma separated) list of levels. For all supported levels see --help output.
-n,
--console-level level
Set the level at which messages are logged to the console. The level is a level number or abbreviation of the level name. For example, -n 1 or -n alert prevents all messages except emergency (panic) messages from appearing on the console. All levels of messages are still written to /proc/kmsg, so syslogd(8) can still control exactly where kernel messages appear. When the -n option is used, dmesg will not print or clear the kernel ring buffer. For all supported levels see --help output.
-r, --raw Print the raw message buffer, i.e., don't strip the log level prefixes.
-s, --buffer-size size Use a buffer of size to query the kernel ring buffer. This is 16392 by default. If you have set the kernel buffer to be larger than the default, then this option can view the entire buffer.
-T, --ctime Print human readable timestamps. The timestamp could be inaccurate; The time source used for the logs is not updated after system SUSPEND/RESUME.
-t, --notime Don't print kernel's timestamps.
-u, --userspace Print userspace messages.
-V, --version Output version information and exit.
-x, --decode Decode facility and level (priority) number to human readable prefixes.

The default action of dmesg is to read all messages from kernel ring buffer.

Examples

dmesg > kernel_msgs.txt

Output all kernel messages currently in the ring buffer to a file called kernel_msgs.txt.

dmesg | grep -i memory

Display only those kernel messages which relate to memory usage.

sysklogd — Linux system logging utilities.