Or copy link
Copy link
The dmesg command is a useful tool in Linux that lets you check what’s happening with your system’s kernel. It helps you see important messages from the kernel, which can be helpful for fixing problems and improving your system’s performance. These kernel messages come from the kernel modules that are loaded when your system starts up.
In this tutorial, we will demonstrate what the dmesg command is and practical examples of using this command in Linux.
The dmesg command displays kernel messages on Unix-like systems, which provide information stored in a special memory area known as the ring buffer. This ring buffer captures important events related to hardware, device driver initialization, and messages from kernel modules during system startup and operation. The basic syntax to use this command is shown below:
dmesg [options]
The common options for dmesg command are listed below, along with their functionalities:
You can learn more about the options available for the Linux dmesg command by typing man dmesg in the terminal. This command opens the manual page for dmesg, where you can see detailed information about its usage, options, and examples:
man dmesg
Read also How to Use the wc Command in Linux
Here are a few examples of the dmesg command that demonstrate its basic usage in Linux:
Let’s run the dmesg command with any optional flag to see its basic functionality in Linux:
sudo dmesg
The output shows that the dmesg command retrieves the system messages related to the Linux kernel.
Explore dmesg Command with Ultahost Linux VPS!
Ultahost’s Linux VPS provides you with full control and flexibility. Its reliable uptime makes it ideal for practicing Linux commands like dmesg with ease.
The dmesg command displays a lot of information, which can be hard to read all at once. To make it easier, you can use commands like tail, head, or less with dmesg to view the logs one page at a time. For example, the below command uses the dmesg with less command to show the system messages page by page:
sudo dmesg | less
You can use the Down Arrow or Enter to scroll line by line in the less viewer, and press q to quit and return to the terminal.
If you want to add colors to make the messages easier to understand, you can colorize them with the -L option:
sudo dmesg -L
To disable the colored output, you can use the “–color=never” option, as follows:
sudo dmesg --color=never
dmesg shows timestamps in seconds and nanoseconds. We can use the -H option with the dmesg command to see the timestamps in a human-friendly format with the date and time:
sudo dmesg -H
You can use the -T (or –ctime) option with the dmesg command to enable human-readable timestamps. This option removes nanosecond details, making the timestamps simpler to read:
sudo dmesg -T
The output below shows that dmesg returns the kernel messages in standard date and time format, which is easily understandable:
We can use the dmesg command with the head command to show a limited/specific number of kernel messages from the top:
sudo dmesg | head -15
This command shows the first 15 kernel messages:
Similarly, we can use the tail command with dmesg to show the last N kernel messages:
sudo dmesg | tail -15
This command shows the last 15 kernel messages:
Each message logged to the kernel ring buffer has a “level” that shows how important the message is. Here are the commonly used levels:
To filter messages by level, we can use the -l (level) option with the dmesg command, followed by the level name. For instance, to list all “warn” level messages, we can use the “dmesg -l warn” command to see the warning notifications:
sudo dmesg -l warn
To find the disk-related messages such as memory, RAM, hard disk, or USB drives, we can use the grep command with dmesg, as follows:
sudo dmesg | grep -i sda
This command uses grep with “sda” to check which hard disks the kernel has detected. The “sda” part refers to hard disk drives; this command will show any messages where “sda” appears:
The -x (decode) option adds the facility and level as prefixes to each line, making them easier to read. For instance, we use the -x option with the dmesg command to display each message’s facility and log level at the beginning of each line:
sudo dmesg -x
Each time our system boots, it saves the kernel ring buffer messages in the /var/log/dmesg file. We can use the dmesg command to view these messages. If we encounter issues with dmesg, we can open the /var/log/dmesg file in a text editor to view the messages directly. For this, first, access the /var/log directory using the Linux cd command:
/var/log/dmesg
/var/log
cd /var/log
Now, use the Linux cat command to view the log file and then pipe it into grep to find a specific word or phrase in the log:
cat dmesg | grep amd
The dmesg command is a useful command line utility for checking kernel messages in Linux. It provides useful information about our system’s hardware and drivers, which helps us fix problems and improve performance. In this tutorial, we discussed several use cases of the dmesg command, such as filtering messages, showing timestamps, viewing logs in an easy-to-read way, etc.
The dmesg command lets you view kernel messages and system events, making it essential for troubleshooting in Linux. For a smoother experience, consider Ultahost’s fast VPS hosting. With various affordable plans, Ultahost ensures reliable uptime, giving you the ideal environment to practice dmesg and other Linux commands effortlessly.
The dmesg command displays messages from the kernel, which can help you understand system events related to hardware and drivers.
It helps users troubleshoot issues by providing important information about system operations, which makes it easier to fix problems and optimize performance.
We can run this command in the terminal with or without any option: “sudo dmesg [option]“.
Some common options include: -C to clear the ring buffer, -H to show human-readable output, -T to view timestamps in a simpler format, and -l to filter messages by their log level (like errors or warnings).
You can use sudo dmesg | less to view the messages page by page. Use the Down Arrow to scroll and press q to quit.
Yes, you can filter messages by their importance level using the -l option, such as dmesg -l warn to see warning messages.
The dmesg logs are stored in the /var/log/dmesg file. You can view them using the command cat /var/log/dmesg.
wc is a command-line utility in Linux that stands for w...
PHP a widely used server-side scripting language plays ...
The pipe command, denoted by the bar "|", is a powerful...
When a Windows user switches to Linux the first thing i...
Port forwarding is a crucial technique for network admi...
The which command in Linux is a simple yet powerful uti...
Save my name, email, and website in this browser for the next time I comment.
Δ