The dmesg (“display message” or “driver message”) command is used to print any messages that have been sent to the kernel’s message buffer during and after system boot. Device drivers send messages to the kernel indicating the status of modules and parameters that the drivers interface with. These drivers can also send diagnostic messages to the kernel in case they encounter errors. Other kernel components can also send messages to the buffer.
In addition to using the dmesg command, you can also access the message buffer from the /var/log/dmesg file. In either case, you can leverage dmesg to look for
potential issues with kernel components or to validate that certain modules are being loaded.
Syntax
The syntax of the dmesg command is:
# dmesg [options]
dmesg Command Options
You can use various options with the dmesg command.
Option | Description |
---|---|
-c | Clear the kernel buffer after printing its contents. |
-f {facility list} | Restrict output to the specified comma-separated list of facilities. A facility is a component category that is producing messages, such as user for user-level messages. |
-l {level list} | Restrict output to the specified comma-separated list of levels. A level defines a message’s nature and priority, such as notice for messages that aren’t considered critical. |
-e | Display a human-readable version of the time of each message as well as its delta, or the difference in time between subsequent messages. |
-L | Color-code messages for easier readability. |
-H | Output in a human-friendly format, combining both -e and -L options and using a text pager. |
-h | List the available options, as well as the available facilities and levels. |
If you encounter the below error while running the dmesg command:
dmesg: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
OS X | brew install util-linux |
Debian | apt-get install util-linux |
Ubuntu | apt-get install util-linux |
Alpine | apk add util-linux |
Arch Linux | pacman -S util-linux |
Kali Linux | apt-get install util-linux |
CentOS | yum install util-linux |
Fedora | dnf install util-linux |
Raspbian | apt-get install util-linux |
dmesg Command Examples
1. To print or control the kernel ring buffer:
# dmesg
2. To clear the kernel ring buffer after printing:
# dmesg -c
3. To print the raw message buffer:
# dmesg -r
4. To specify the ring buffer size:
# dmesg -s 1024
5. To set the level of logging:
# dmesg -n level # dmesg -n 1 ## prevent all messages
6. Show kernel error messages:
# dmesg --level err
7. Show kernel messages and keep reading new ones, similar to `tail -f` (available in kernels 3.5.0 and newer):
# dmesg -w
8. Show how much physical memory is available on this system:
# dmesg | grep -i memory
9. Show kernel messages 1 page at a time:
# dmesg | less
10. Show kernel messages with a timestamp (available in kernels 3.5.0 and newer):
# dmesg -T
11. Show kernel messages in human-readable form (available in kernels 3.5.0 and newer):
# dmesg -H
12. Colorize output (available in kernels 3.5.0 and newer):
# dmesg -L