Understanding dmesg -n: Controlling Linux Kernel Messages
On Linux, the dmesg command is an essential tool for any system administrator. It allows you to view or control the kernel ring buffer, which is the circular memory where system messages generated by the kernel are stored.
These messages typically include:
- System startup and hardware detection
- Driver loading
- Hardware errors
- Other critical events related to the operating system’s functioning
With dmesg, you can monitor your system’s internal activity in real time, much like a “kernel journal.”
The -n Option: Filtering Messages Displayed on the Console
By default, the Linux kernel sends all messages (from critical to minor) to the console. This verbosity can quickly become overwhelming, especially on a production server.
The -n option (or --console-level) allows you to set the minimum priority level for messages that are sent to the system console—meaning the messages that appear in real time on the terminal, not the output of the dmesg command itself.
👉 In other words, dmesg -n doesn’t filter what you see when you run dmesg; it controls what the system automatically displays on the console.
Kernel Message Priority Levels
The Linux kernel categorizes messages according to a severity level ranging from 0 (emergency) to 7 (debug). Here’s the complete table:
| Level | Name | Description |
|---|---|---|
| 0 | emerg | Critical system failure (system is unusable) |
| 1 | alert | Immediate action required |
| 2 | crit | Critical error |
| 3 | err | Standard error |
| 4 | warning | Warning |
| 5 | notice | Important informational message |
| 6 | info | General informational message |
| 7 | debug | Detailed debugging message |
Practical Example: dmesg -n 3
The following command:
sudo dmesg -n 3means that only messages with levels 0 to 3 will be displayed on the console. In other words:
- emerg
- alert
- crit
- err
All lower-priority messages (warning, notice, info, debug) will be ignored by the console. This is very useful to reduce visual clutter on production servers or critical environments.
Practical Use Cases
Display Only Critical Errors
sudo dmesg -n 3Enable All Messages
sudo dmesg -n 7This allows all message levels, including debug messages (debug).
View the Full Kernel Log
dmesg | lessThis command is not affected by the -n level, since it reads the kernel buffer directly.
Making the Configuration Persistent
The setting applied with dmesg -n is not retained after a reboot. To apply it automatically at boot, add it to a startup script:
sudo nano /etc/rc.local
# Add the following line
dmesg -n 3
# End the file with
exit 0
sudo chmod +x /etc/rc.local
You can also configure this using systemd by creating a custom service if rc.local is not available.
Best Practices for System Administrators
- ✅ Use
dmesg -n 3on production servers to prevent non-critical message spam. - 🔍 On test or development machines, keep the level at 7 for full informational output.
- 🧾 Monitor detailed logs via
journalctl -kor/var/log/kern.log. - 🕹️ Include the command in initialization scripts to automate console verbosity management.
Conclusion
The dmesg -n command is a simple yet powerful tool to control the amount of kernel messages displayed on the console. By adjusting the priority level, you can achieve a clearer, more relevant output suitable for your environment.
In summary:
dmesg→ displays kernel messages-n→ controls verbositydmesg -n 3→ shows only critical errors on the console
This configuration is ideal for keeping Linux servers clean, quiet, and under control.
Written by: Christian – Nitrohost


