dmesg

system managementLinux/Unix
The dmesg command is one of the most frequently used commands in Linux/Unix-like operating systems. dmesg Display or control the kernel ring buffer messages

Quick Reference

Command Name:

dmesg

Category:

system management

Platform:

Linux/Unix

Basic Usage:

dmesg [options] [arguments]

Common Use Cases

    Syntax

    dmesg [options]

    Options

    Option Description
    -c, --clear Clear the ring buffer after printing
    -C, --read-clear Clear the ring buffer after printing and only print new messages
    -f, --facility list Restrict output to defined facilities
    -l, --level list Restrict output to defined levels
    -n, --console-level level Set level of messages printed to console
    -r, --raw Print the raw message buffer
    -s, --buffer-size size Buffer size to query the kernel
    -T, --ctime Show human-readable timestamps
    -w, --follow Wait for new messages
    --since=time Show only records since the specified time
    --until=time Show only records until the specified time

    Examples

    How to Use These Examples

    The examples below show common ways to use the dmesg command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    dmesg
    Display all kernel messages from the ring buffer.
    dmesg | grep -i usb
    Filter kernel messages to show only USB-related entries.
    dmesg -c
    Clear the ring buffer after printing its contents. # Advanced Examples Advanced dmesg -T Display timestamps in human-readable format. dmesg -l err,warn Show only error and warning messages. dmesg -f syslog Display only syslog facility messages. dmesg -w Display new messages as they appear (follow mode). dmesg --since=1h Show messages from the last hour.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Dmesg Command Overview: The dmesg command displays messages from the kernel ring buffer. The ring buffer is a data structure that records messages related to the kernel's operation, including hardware device information, driver initialization, system errors, and more. Key Features: - Displays kernel bootup messages - Shows hardware detection information - Reveals driver loading/unloading events - Displays kernel errors and warnings - Can monitor for new kernel messages in real-time Common Uses: - Troubleshooting hardware issues - Identifying driver problems - Monitoring system boot process - Investigating system crashes or instability - Debugging kernel-related issues Message Levels: - emerg: System is unusable - alert: Action must be taken immediately - crit: Critical conditions - err: Error conditions - warn: Warning conditions - notice: Normal but significant conditions - info: Informational messages - debug: Debug-level messages The dmesg command is particularly useful for system administrators and developers when diagnosing system issues, especially those related to hardware devices, kernel modules, or system initialization.

    Related Commands

    These commands are frequently used alongside dmesg or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the dmesg command works in different scenarios.

    $ dmesg
    View All Commands