dmesg — Read the Kernel Ring Buffer and Diagnose Hardware Issues
Practical guide to dmesg — read kernel messages about hardware, drivers and OOM events, follow them live, filter by level and format timestamps.
dmesg prints the kernel ring buffer – the bounded memory region where the Linux kernel records messages about hardware detection, driver initialisation, USB events, disk errors and the OOM killer. When a device isn't recognised, the system stalls intermittently, or a process is killed for no obvious reason, dmesg is usually the first place to look. On modern distributions the buffer is often readable only with sudo for security reasons (kernel.dmesg_restrict). This guide shows you how to format messages legibly, filter them precisely and watch them live.
Basic Usage
dmesg — Show all kernel messages from the ring buffer.
dmesgdmesg | less — Page through kernel messages.
dmesg | lessdmesg | tail -30 — Show the last 30 kernel messages.
dmesg | tail -30sudo dmesg — Show kernel messages (may require root on some systems).
sudo dmesgTimestamps & Formatting
dmesg -T — Show human-readable timestamps instead of seconds since boot.
dmesg -Tdmesg -t — Do not print timestamps at all.
dmesg -tdmesg --time-format iso — Show timestamps in ISO 8601 format.
dmesg --time-format isodmesg -x — Decode facility and level to readable prefixes.
dmesg -xdmesg --color=always — Force colorized output (useful when piping).
dmesg --color=always | less -Rdmesg -H — Human-readable output with color and pager.
dmesg -HFiltering by Level
dmesg -l err — Show only error messages.
dmesg -l errdmesg -l warn — Show only warning messages.
dmesg -l warndmesg -l crit — Show only critical messages.
dmesg -l critdmesg -l emerg — Show only emergency messages (system is unusable).
dmesg -l emergdmesg -l info — Show only informational messages.
dmesg -l infodmesg -l err,warn — Show errors and warnings combined.
dmesg -l err,warndmesg -l err,crit,alert,emerg — Show all serious messages.
dmesg -l err,crit,alert,emergFiltering by Facility
dmesg -f kern — Show only kernel messages.
dmesg -f kerndmesg -f daemon — Show only daemon messages.
dmesg -f daemondmesg -f user — Show only user-space messages.
dmesg -f userdmesg -f syslog — Show only syslog messages.
dmesg -f syslogFollowing & Clearing
dmesg -w — Follow/watch mode — continuously print new kernel messages (like tail -f).
sudo dmesg -wdmesg -W — Follow and wait — only show new messages (skip existing buffer).
sudo dmesg -Wdmesg -c — Print and clear the ring buffer. Requires root.
sudo dmesg -cdmesg -C — Clear the ring buffer without printing. Requires root.
sudo dmesg -Cdmesg -D — Disable printing messages to the console.
sudo dmesg -Ddmesg -E — Enable printing messages to the console.
sudo dmesg -ESearching for Specific Events
dmesg | grep -i error — Search for error messages (case-insensitive).
dmesg | grep -i errordmesg | grep -i 'usb' — Show USB-related kernel messages.
dmesg | grep -i 'usb'dmesg | grep -i 'eth\|ens\|enp' — Show network interface-related messages.
dmesg | grep -i 'eth\|ens\|enp'dmesg | grep -i 'sd[a-z]\|nvme' — Show disk/storage device messages.
dmesg | grep -i 'sd[a-z]\|nvme'dmesg | grep -i 'oom\|out of memory' — Check for out-of-memory killer events.
dmesg | grep -i 'oom\|out of memory'dmesg | grep -i 'segfault\|general protection' — Look for segmentation faults and protection errors.
dmesg | grep -i 'segfault\|general protection'dmesg | grep -i 'firmware' — Show firmware loading messages.
dmesg | grep -i 'firmware'Common Patterns
dmesg -T -l err,warn — Show errors and warnings with human-readable timestamps.
dmesg -T -l err,warndmesg -T | tail -50 — Show the 50 most recent kernel messages with timestamps.
dmesg -T | tail -50dmesg -Tw — Follow kernel messages with human-readable timestamps.
sudo dmesg -Twdmesg --since '1 hour ago' — Show messages from the last hour (requires recent dmesg).
dmesg --since '1 hour ago'dmesg --until '2024-01-01 12:00' — Show messages until a specific time.
dmesg --until '2024-01-01 12:00'dmesg -T > dmesg_$(date +%Y%m%d).log — Save kernel messages with timestamps to a dated log file.
dmesg -T > dmesg_$(date +%Y%m%d).log Conclusion
dmesg is a read-only command and therefore largely harmless – the sole exception is dmesg -C, which clears the ring buffer irreversibly and destroys forensic evidence in the process. For diagnostics it pays to make messages legible with -T and boil them down to what matters with -l err,warn; dmesg -w follows events live, for example when you plug in a USB device. On systems with kernel.dmesg_restrict=1 you'll need sudo. In substance dmesg overlaps heavily with journalctl -k, which keeps the same kernel messages persistently and across reboots – often the better choice for long-term analysis.
Further Reading
- Wikipedia: dmesg – background on the kernel ring buffer and the command
- Arch Wiki: General troubleshooting – using kernel logs to diagnose system problems
Related Commands
- journalctl – query the systemd journal, including kernel messages via
journalctl -k - strace – trace a process's system calls when dmesg points to a problem
- lsof – list open files and devices, complementing hardware diagnostics