dmesg command displays messages retrieved from the kernel ring buffer during boot. It contains a lot of useful informations about hardware, kernel modules and device drivers. In case of hardware failure, the dmesg gives all required informations. It is frequently combined with commands such as grep, less, more, tail or head.
Syntax :
dmesg [options]
sudo dmesg
The above command displays all contents of the kernel buffer non-stop, without pauses or navigation capabilities. So we should use instead :
sudo dmesg | less
1.1 Display first 30 Lines : the very early stages of the system startup process such as: Kernel Version and Build Information, CPU Information, Initial Hardware Detection, etc...
sudo dmesg | head -30
1.2 Display last 30 Lines : Device Driver Activity, hardware Events such as detection of new hardware, hot-plugging of devices, or hardware-related errors, system Errors and Warnings, etc...
sudo dmesg | tail -n 30
SATA hard disks :
sudo dmesg | grep sda
memory : with ‘-i’ option grep will be case-insensitive.
sudo dmesg | grep -i memory
network :
sudo dmesg | grep -i eth
USB :
sudo dmesg | grep -i USB
3.1human-readable
-H (--human) option, generates human-readable output and pipes the output to less
sudo dmesg -H
3.2 Choose Timestamp Format
Use the --time-format=[format] from the options below :
sudo dmesg -T | grep -i sda
The -f option allows us to restrict the output to messages belonging to one or more specified facilities (categories).
Syntax :
sudo dmesg -f <facility1>,<facility2>
Commonly used facilities include:
Example : Display kernel and user-level messages:
sudo dmesg -f kern,user
The -l option allows us to filter by log level. This restricts the output to messages of a specific severity.
Syntax :
sudo dmesg -l <level1>,<level2>
Common log levels (ordered by severity) include:
Example : Display only error and warning messages:
sudo dmesg -l err,warn
source :