The dmesg command displays messages from the Linux kernel, including hardware detection, driver activity, and system errors. If the output is long or contains old messages, you may want to clear the kernel message buffer. On most Linux systems, the direct command is sudo dmesg --clear. However, clearing the buffer is not the same as deleting kernel messages saved by system logging services, and it can remove information that would help diagnose a problem. This guide explains how to clear dmesg logs, check that the command worked, and understand what it does—and does not—remove.
What Does dmesg Store?
dmesg reads messages from the kernel’s ring buffer. The kernel writes information there while the system runs, such as details about connected devices, drivers, memory, and hardware or software errors. Because the buffer has a limited size, newer messages eventually replace older ones.
The buffer is mainly a temporary record of kernel activity. It is useful when troubleshooting boot problems, device failures, network issues, and other system behavior. You can display its current contents with:
dmesg
On some distributions, ordinary users cannot read all kernel messages. In that case, run the command with elevated privileges:
sudo dmesg
Clearing the ring buffer removes its current messages from the buffer. It does not uninstall drivers, change kernel settings, repair an error, or necessarily erase copies that a logging service has already saved.
How to Clear dmesg Logs
The standard way to clear the kernel ring buffer is to use the --clear option. The short form is an uppercase -C:
sudo dmesg --clear
Or use the equivalent short option:
sudo dmesg -C
The command usually completes without printing a confirmation message. That is normal. When it succeeds, the messages currently stored in the kernel ring buffer are cleared. The system continues to operate, and the kernel begins adding new messages as events occur.
To check the result, display the buffer again:
sudo dmesg
If the output is empty or contains only messages created after the clear operation, the buffer has been cleared. You can also print a short view of the latest messages with:
sudo dmesg | tail
Remember that a quiet buffer does not mean the computer has no issues. It only means there are few or no messages currently available in that particular buffer.
Using dmesg to Read and Clear the Buffer
Some versions of dmesg also support --read-clear, which reads the messages and then clears the ring buffer. Its short form is lowercase -c:
sudo dmesg --read-clear
This differs from --clear. Use --clear when you want to discard the current buffer without first displaying it. Use --read-clear when you want to capture the existing messages in the terminal and then clear them. You can save the output before clearing it by redirecting it to a file:
sudo dmesg --read-clear > kernel-messages.txt
Option availability and behavior can depend on the installed dmesg version. Check the local manual page if an option is rejected:
man dmesg
For most users, sudo dmesg --clear is the simplest and clearest choice when the goal is only to empty the current ring buffer.
Why You May Need sudo
Linux controls access to kernel messages because they can reveal details about hardware, devices, and system activity. Depending on the distribution and security configuration, a regular account may be allowed to read only some messages—or may not be allowed to read them at all. Clearing the buffer also typically requires elevated privileges.
If you see a “permission denied” message, try the command with sudo:
sudo dmesg --clear
If sudo is unavailable, sign in with an authorized administrator account or ask your system administrator. Avoid changing security settings just to make dmesg easier to access. For example, Linux systems may restrict access using the kernel.dmesg_restrict setting. Disabling that protection can expose kernel information to untrusted users and is usually unnecessary for clearing the buffer with administrator privileges.
Does Clearing dmesg Delete Journal or Log Files?
No. This distinction is important. The dmesg --clear command clears the kernel’s in-memory ring buffer. On systems using systemd, kernel messages may also be collected by the journal. Other distributions may write kernel messages to files such as /var/log/kern.log or /var/log/messages.
Those saved records can remain available after you clear the ring buffer. For example, this command displays kernel messages recorded by the systemd journal:
journalctl -k
To show recent kernel journal entries, use:
journalctl -k -n 50
Clearing the dmesg ring buffer does not remove those journal entries. Similarly, it does not erase kernel messages already written to traditional log files. This is often helpful: you can clear the live buffer while keeping the historical records needed for troubleshooting or auditing.
If you intend to manage stored logs, use the logging system’s documented retention controls rather than deleting files manually. Journal cleanup commands can affect more than kernel messages and may remove records needed by other applications or administrators. Review what a command will remove before using it, especially on a production server.
What Happens After You Clear the Buffer?
Clearing the buffer does not stop the kernel from recording messages. New messages appear as the system continues to run. For instance, connecting a USB device, starting a driver, or encountering an error may add fresh entries immediately after the clear operation.
This makes clearing useful during troubleshooting when you want to focus on events that happen after a specific point. You can clear the existing messages, reproduce the issue, and then inspect the new entries:
sudo dmesg --clear
# Reproduce the issue
sudo dmesg
In a real terminal, enter each command separately; the comment simply marks the point where you perform the action you are investigating. If you need to preserve the results, save the new output to a file:
sudo dmesg > dmesg-after-test.txt
Consider saving or reviewing useful messages before clearing the buffer. Once removed from the ring buffer, older entries may no longer be available there. They might still exist in the system journal or log files, but you should not rely on that unless you have confirmed logging is enabled and the records are retained.
Common Problems and Fixes
-
“Operation not permitted” or “Permission denied”: Retry with
sudo. If you do not have administrator rights, ask someone authorized to run the command. -
“Invalid option”: Confirm that you typed two hyphens before
clear, or use uppercase-C. Checkman dmesgbecause older or different implementations may offer different options. - Messages appear again immediately: The clear operation may have worked, but new kernel activity can refill the buffer. Check the timestamps and reproduce the test in a quiet period if necessary.
- Old messages still appear in journalctl: This is expected. The journal is a separate record from the live kernel ring buffer, and clearing one does not automatically erase the other.
-
The output is too large to inspect: Filter or limit what you display instead of clearing it. For example,
sudo dmesg --level=err,warnshows messages at selected severity levels, whilesudo dmesg | tail -n 30displays the latest 30 lines.
Be cautious about using shell redirection as a substitute for the clear option. A command such as dmesg > file.txt saves output; it does not clear the ring buffer. Likewise, removing a log file from /var/log is not the correct way to clear dmesg and may interfere with the logging service.
Should You Clear dmesg Logs?
Clearing the buffer is generally a routine administrative action, but it is not always the best first step. If the system is malfunctioning, inspect the existing messages before removing them. They may contain the only immediately available clues about what happened. Save relevant output first when you are investigating a recurring or serious problem.
On a shared computer, managed server, or work device, follow local logging and incident-response policies. Kernel logs can be important for security reviews and troubleshooting, and clearing them without authorization may remove useful evidence from the live buffer. Also remember that clearing the ring buffer does not make the system’s history disappear if a journal or other log service has retained it.
If your only goal is to get a clean set of messages before testing a device or reproducing an error, clearing the buffer is often useful. If your goal is to reduce disk usage or erase stored system history, dmesg --clear will not accomplish that; use the appropriate log-retention process instead.
Conclusion
To clear dmesg logs in Linux, run sudo dmesg --clear or its equivalent, sudo dmesg -C. Then run sudo dmesg to check the current ring buffer. Use sudo dmesg --read-clear if you want to display the existing messages before clearing them, and save important output if you may need it later.
The key point is that dmesg clearing affects the kernel’s live ring buffer—not necessarily messages already stored by the system journal or log files. Knowing the difference helps you clear the right information, preserve useful diagnostic records, and avoid deleting logs unnecessarily.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.