To clear the Linux dmesg buffer, run sudo dmesg -C. This clears the kernel’s current in-memory message buffer; it does not erase saved system logs or prevent new messages from appearing. If you want to view the messages and clear them in one step, use sudo dmesg -c instead.
dmesg displays messages from the Linux kernel, including hardware detection, driver activity, and some system errors. Clearing its buffer can make it easier to focus on messages generated during a test or troubleshooting session. Before you clear it, make sure you understand what is being removed and whether you need to save a copy.
How to Clear the dmesg Buffer
Open a terminal and enter:
sudo dmesg -C
The -C option tells dmesg to clear the kernel ring buffer. You may be asked for your account password. If the command succeeds, it may return no output; that is normal. You can then check the buffer with:
sudo dmesg
If there have been no new kernel messages since you cleared it, the command may display nothing. On an active system, however, the kernel can generate new messages immediately, so the buffer may not stay empty.
What Does “Clear dmesg” Actually Mean?
The messages shown by dmesg are held in a kernel ring buffer. A ring buffer is a limited area of memory where newer entries replace older ones as it fills. Clearing the buffer removes the messages currently stored there, giving you a fresh starting point for observing new kernel activity.
This operation does not clear the computer’s memory, uninstall drivers, repair hardware, or change kernel settings. It also does not normally remove copies of kernel messages that another logging service has already saved. Think of dmesg -C as clearing one temporary view of kernel activity, not as erasing every record of it from the system.
The buffer can begin filling again as soon as the kernel reports another event. For example, connecting a USB device, starting a driver, or encountering a hardware error may add new lines. Therefore, seeing output after clearing does not necessarily mean the command failed.
Difference Between dmesg -C and dmesg -c
Linux provides two commonly used options to clear the kernel message buffer. They differ in whether they display the existing messages as part of the operation:
-
sudo dmesg -Cclears the buffer without first printing its contents. -
sudo dmesg -cprints the current messages and then clears the buffer.
Use -C when you simply want to start with an empty buffer. Choose -c when you want to capture or review the messages immediately before they are removed. Because -c prints the output, consider where that output goes: it may appear in your terminal or be saved if you redirect it.
For example, to save the current messages to a file while clearing the buffer, run:
sudo dmesg -c > "$HOME/dmesg-before-clear.txt"
This can be useful before reproducing an issue, since you can preserve the earlier messages and then examine new activity separately. Treat saved kernel logs as potentially sensitive: they may reveal device details, system configuration, or other diagnostic information.
Do You Need sudo to Clear dmesg?
On many Linux distributions, clearing the kernel ring buffer requires administrator privileges. If running dmesg -C returns a permission error, try:
sudo dmesg -C
Access to kernel messages is controlled partly to protect information that could reveal details about the system. Depending on your Linux distribution, kernel version, and security configuration, permissions may also affect whether you can read or clear the buffer. The kernel setting kernel.dmesg_restrict is one control that can limit access to kernel logs.
If sudo still does not work, your account may not have permission to use it, or a system policy may restrict the operation. Ask your system administrator rather than trying to bypass the restriction. On a managed server or shared machine, kernel logs may contain information that administrators intentionally keep restricted.
How to Check Whether the Buffer Was Cleared
After running sudo dmesg -C, read the buffer again:
sudo dmesg
An empty result suggests that no messages have been added since the clear operation. If you see a few entries, they may be new messages generated afterward. To make the check more useful, note the time you cleared the buffer and compare it with the timestamps or content of the messages that follow.
For readable timestamps on many systems, you can use:
sudo dmesg -T
The -T option converts kernel timestamps into a human-readable date and time where supported. These converted times can be approximate, so use them as a troubleshooting aid rather than as a precise audit record.
Another practical approach is to clear the buffer immediately before performing one specific action, such as reconnecting a device. Then run sudo dmesg again and look for messages related to that action. Remember that other system activity may also produce entries during the same period.
Why Is dmesg Still Showing Old Messages?
If messages appear to remain after you clear dmesg, first confirm that the command completed without an error and that you used the correct option. sudo dmesg -C clears the buffer; a command that only reads it, such as sudo dmesg, does not.
Also check whether the lines you are viewing are genuinely new. Kernel messages may be generated between clearing the buffer and running the next command. On a busy system, that can happen quickly. Repeating the clear-and-check sequence during a quiet period can help confirm the behavior.
Finally, make sure you are looking at the right source. A terminal command such as dmesg reads the current kernel buffer, while a graphical log viewer or system journal may show stored messages from an earlier time. Clearing one source does not necessarily clear the others.
Does Clearing dmesg Delete Journal or System Logs?
No. Clearing the kernel ring buffer with dmesg -C is different from removing records saved by a logging service. On systems using systemd, kernel messages may also be available through the journal. You can view kernel-related journal entries with:
journalctl -k
That command reads journal records; it does not clear the current dmesg buffer. Similarly, clearing the buffer with dmesg -C does not erase historical journal entries that were already stored. The journal’s retention and cleanup policies are separate from the kernel ring buffer.
This distinction matters when troubleshooting. If you need a clean buffer to watch new kernel events, use dmesg -C. If you need to inspect earlier events, check the relevant system logs before assuming that clearing the buffer removed all evidence. Avoid deleting or vacuuming system logs unless you specifically intend to change log retention and understand the consequences.
Common Reasons to Clear the dmesg Buffer
Clearing the buffer can be helpful when you want to separate new kernel messages from older, unrelated output. Common examples include:
- Testing whether a device connection creates kernel or driver errors.
- Checking what messages appear when a service or module starts.
- Monitoring a reproducible hardware problem.
- Reducing clutter before collecting diagnostic output for a support request.
- Running a short troubleshooting test and reviewing only the messages generated afterward.
Clearing the buffer is not, by itself, a fix for a kernel warning or hardware fault. If concerning messages return, save the output and investigate the device, driver, or system event that caused them. A fresh buffer can help narrow down when a message occurs, but the message’s meaning still depends on the surrounding system context.
Useful Safety and Troubleshooting Tips
Before clearing the buffer, save the current output if it might help diagnose an existing problem. For example, sudo dmesg > "$HOME/dmesg-backup.txt" writes a copy to a file in your home directory. Confirm that the command finishes successfully and that you can access the saved file before clearing anything.
Be careful when sharing kernel logs publicly. Output can include hardware identifiers, device names, filesystem details, or other information about your computer. Review the file and remove sensitive details if necessary. On a production system, follow your organization’s logging and incident-response procedures.
If an option is unavailable, check your installed version of the utility with dmesg --help or man dmesg. Linux distributions can ship different versions of the util-linux tools, and system policies may affect which operations are permitted. Do not assume that a command for Linux will work on a different operating system.
Conclusion: The Quickest Way to Clear dmesg
To clear the current Linux kernel message buffer, run sudo dmesg -C. Use sudo dmesg -c if you want to print the existing messages and clear them in one step. Then check the buffer with sudo dmesg, keeping in mind that new kernel messages can appear immediately.
Most importantly, clearing dmesg removes only the current in-memory buffer. It does not automatically erase historical entries saved by the system journal or other logging services. Save useful output before clearing it, and investigate any errors that return rather than treating the clear command as a repair.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.