Skip to main content

Command Palette

Search for a command to run...

Cheat Sheet #day30 - dmesg

Published
2 min read
Cheat Sheet #day30 - dmesg

dmesg Cheatsheet

Basic Usage

  • Display the kernel ring buffer messages:

      dmesg
    

Filtering Output

  • Filter messages using grep:

      dmesg | grep <pattern>
    
  • Show messages with timestamps:

      dmesg -T
    

Controlling Output

  • Clear the ring buffer (requires root):

      sudo dmesg -C
    
  • Limit the number of lines displayed:

      dmesg | tail -n <number_of_lines>
    
  • Show messages in real-time:

      dmesg -w
    

Specific Message Types

  • Show only kernel messages:

      dmesg -k
    
  • Show only userspace messages:

      dmesg -u
    
  • Show messages by facility (e.g., auth, daemon, kern, etc.):

      dmesg -f <facility>
    
  • Show messages by level (e.g., emerg, alert, crit, err, etc.):

      dmesg -l <level>
    

Time and Date Formatting

  • Show human-readable timestamps:

      dmesg -H
    
  • Show messages with nanosecond timestamps:

      dmesg -L
    

Kernel Log Buffer Size

  • Display the size of the kernel log buffer:

      dmesg -s <buffer_size>
    

Advanced Usage

  • Decode devicetree boot messages:

      dmesg -D
    
  • Display raw message buffer data:

      dmesg -r
    

Redirecting Output

  • Save output to a file:

      dmesg > /path/to/file
    
  • Append output to a file:

      dmesg >> /path/to/file
    

Example Commands

  • Filter for USB-related messages:

      dmesg | grep -i usb
    
  • Show only error messages:

      dmesg -l err
    
  • Follow new kernel messages in real-time:

      dmesg -wH
    
  • Clear the ring buffer and display messages:

      sudo dmesg -C && dmesg
    

This cheatsheet provides a quick reference to the most commonly used dmesg commands and options. dmesg is a powerful tool for system administrators and developers to troubleshoot and monitor system activity by accessing kernel messages.

More from this blog

Cloud Tuned

621 posts

Your starting point for anything cloud: AWS, Azure, GCP, Serverless, Architecture, Hybrid Cloud, Systems Design and other Information Technology topics.