1. Display All Kernel Messages
$ dmesg
Shows all messages in the kernel ring buffer. This output can be quite long, often thousands of lines containing boot messages, hardware detection, and system events.
What you'll see: Timestamps, subsystem identifiers, and message text describing kernel activities from boot to present.
journalctl -k
2. Display with Human-Readable Timestamps
$ dmesg -T
Shows messages with human-readable timestamps instead of seconds since boot. The -T flag translates kernel timestamps to actual date/time format.
Example output: [Mon Nov 3 14:23:45 2025] instead of [12345.678901]
3. Watch Kernel Messages in Real-Time
$ dmesg -w
Enables "follow mode" similar to tail -f, continuously displaying new kernel messages as they appear. This is invaluable for real-time troubleshooting.
Behavior: The command stays running and prints new messages immediately. Press Ctrl+C to exit.
dmesg -wT
4. Filter by Log Level (Errors Only)
$ dmesg -l err,crit,alert,emerg
Displays only messages at error level or higher. This filters out informational messages and focuses on actual problems.
Levels included:
- emerg - System is unusable
- alert - Action must be taken immediately
- crit - Critical conditions
- err - Error conditions
5. Search for Specific Hardware or Driver
$ dmesg | grep -i usb
Filters dmesg output to show only lines containing "usb" (case-insensitive). This is useful for focusing on specific subsystems.
Common searches: usb, eth, wlan, sata, bluetooth, nvidia, amd, cpu, memory, disk
dmesg | grep -i 'error\|fail\|warn' to find all problematic messages.
6. Show Last 20 Messages
$ dmesg | tail -20
Displays only the most recent 20 kernel messages. Perfect for quick checks of recent activity without scrolling through thousands of lines.
Why this works: Kernel messages are chronological, so the last messages are the most recent events.
dmesg -w | tail -20
7. Clear the Ring Buffer (Root Only)
$ sudo dmesg -C
Clears the kernel ring buffer, removing all current messages. This requires root privileges as it affects system-wide logging.
Important: Messages are cleared from the ring buffer but may still exist in system logs (journalctl, /var/log/kern.log).
dmesg > /tmp/dmesg-backup.txt
8. Display with Facility Information
$ dmesg -x
Shows messages with both facility and level information in a more structured format. This helps identify which kernel subsystem generated each message.
Format: Each line is prefixed with facility (kern, user, daemon, etc.) and priority level.
9. Show Boot Messages Only
$ dmesg | head -100
Displays the first 100 lines of kernel output, which typically contains boot messages. These show hardware initialization, driver loading, and early system setup.
What's in boot messages: CPU detection, memory initialization, PCI device enumeration, disk detection, filesystem mounting.
journalctl -k -b shows kernel messages from current boot only.
10. Color-Coded Output by Severity
$ dmesg -L
Enables colored output where different severity levels are displayed in different colors. This makes it much easier to spot errors and warnings at a glance.
Typical colors:
- Red - Errors and critical messages
- Yellow/Orange - Warnings
- Normal - Informational messages
dmesg -TL gives you human timestamps AND colors!
Kernel Message Severity Levels
| Level | Number | Description |
|---|---|---|
| emerg | 0 | Emergency - System is unusable |
| alert | 1 | Alert - Action must be taken immediately |
| crit | 2 | Critical - Critical conditions |
| err | 3 | Error - Error conditions |
| warn | 4 | Warning - Warning conditions |
| notice | 5 | Notice - Normal but significant condition |
| info | 6 | Informational - Informational messages |
| debug | 7 | Debug - Debug-level messages |
Quick Reference: Common dmesg Options
| Option | Description |
|---|---|
-T |
Show human-readable timestamps |
-w |
Watch/follow mode (continuous output) |
-L |
Colorize output by severity |
-l [level] |
Filter by log level (err, warn, info, etc.) |
-x |
Show facility and level information |
-C |
Clear the ring buffer (requires root) |
-H |
Human-readable output (similar to -T) |
-k |
Show kernel messages only |
-u |
Show userspace messages only |
--since |
Show messages since specified time |
--until |
Show messages until specified time |
- USB not recognized:
dmesg -wT | grep -i usb - Disk errors:
dmesg -l err | grep -i 'sd\|sata' - Network issues:
dmesg | grep -i 'eth\|wlan\|network' - Out of memory:
dmesg | grep -i 'oom\|memory' - Hardware failures:
dmesg -l err,crit,alert,emerg
sudo dmesg -T > ~/dmesg-before-upgrade-$(date +%Y%m%d).txtThis creates a timestamped backup for comparison if issues arise.