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 -CLimit 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 -kShow only userspace messages:
dmesg -uShow 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 -HShow 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
devicetreeboot messages:dmesg -DDisplay raw message buffer data:
dmesg -r
Redirecting Output
Save output to a file:
dmesg > /path/to/fileAppend output to a file:
dmesg >> /path/to/file
Example Commands
Filter for USB-related messages:
dmesg | grep -i usbShow only error messages:
dmesg -l errFollow new kernel messages in real-time:
dmesg -wHClear 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.




