Here's a comprehensive guide on the dmesg command, covering:
✅ What is dmesg
📘 Syntax
🔧 Practical Examples
⚠️ Edge Cases
🧠 FAANG-level 20 Interview Questions with Answers
✅ What is dmesg?
dmesg stands for "diagnostic message".
It reads and displays the kernel ring buffer, showing boot-time messages, hardware errors, driver logs, and system events.
Logs include:
Device initialization (e.g., disk, USB, network)
Kernel panics, oops
Memory errors
Module loading/unloading
Driver issues
Crash dump info
It's especially useful for debugging hardware-level issues.
📘 dmesg Syntax
dmesg [options]
Common Options:
🔧 Hands-On Examples
1. View All Kernel Messages
dmesg
2. Human-Readable Time
dmesg -T
3. Real-Time Logging
dmesg -w
4. Filter Only Errors
dmesg --level=err
5. Search USB Events
dmesg | grep -i usb
6. Boot Logs with Time
dmesg -T | less
7. Detect Disk Issues
dmesg | grep -i sda
⚠️ Edge Cases and Advanced Use
❗ 1. Messages are Cleared After Reboot
The kernel ring buffer is volatile. Logs are lost on reboot unless captured by journald or syslog.
❗ 2. Buffer Overflow
If there’s too much kernel activity, older messages get overwritten. Use:
dmesg --ctime | tail -n 1000 > backup.log
❗ 3. No Timestamps by Default
Use -T to show readable timestamps. Default format is epoch-based.
❗ 4. Not Color-Coded
Unlike journalctl, dmesg output is plain. Use filters or tools like ccze for color.
❗ 5. Non-root Behavior
Non-root users might not see full logs. Use sudo for full access:
sudo dmesg
❗ 6. audit or apparmor noise
Systems with AppArmor/SELinux/Audit may flood dmesg with permission logs.