dmesg command in Linux for driver messages

dmesg command also called as “driver message” or “display message” is used to examine the kernel ring buffer and print the message buffer of kernel. The output of this command contains the messages produced by the device drivers.

Usage of dmesg :

When the computer boots up, there are lot of messages(log) generated during the system start-up.
So you can read all these messages by using dmesg command. The contents of kernel ring buffer are also stored in /var/log/dmesg file.

The dmesg command can be useful when system encounters any problem during its start-up, so by reading the contents of dmesg command you can actually find out where the problem occurred(as there are many steps in system boot-up sequence).

Syntax :

dmesg [options]

Options :

-C –clear : clear the ring buffer.
-c –read-clear : clear the ring buffer after printing its contents.
-D –console-off : disable the messages printing to console.
-E –console-on : Enable printing messages to console.
-F –file file : read the messages from given file.
-h –help : display help text.
-k –kernel : print kernel messages.
-t –notime : do not print kernel’s timestamps.
-u –userspace : print userspace messages.

You can check more options here

Since output of dmesg command is very large, so for finding specific information in dmesg output, it is better to use dmesg command with less or grep command.

dmesg | less 

or 

dmesg | grep "text_to_search"

For example :
This is output of dmesg command when I plugged in USB drive and then unplugged it.
This is part of output of dmesg command, since output is very large, you can try on your Linux terminal

[ 6982.128179] usb 2-2: New USB device found, idVendor=0930, idProduct=6544
[ 6982.128185] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 6982.128188] usb 2-2: Product: DataTraveler 2.0
[ 6982.128190] usb 2-2: Manufacturer: Kingston
[ 6982.128193] usb 2-2: SerialNumber: C86000886407C141DA1401A2
[ 6982.253866] usb-storage 2-2:1.0: USB Mass Storage device detected
[ 6982.254035] scsi host3: usb-storage 2-2:1.0
[ 6982.254716] usbcore: registered new interface driver usb-storage
[ 6982.265103] usbcore: registered new interface driver uas
[ 6983.556572] scsi 3:0:0:0: Direct-Access Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 4
[ 6983.557750] sd 3:0:0:0: Attached scsi generic sg1 type 0
[ 6983.557863] sd 3:0:0:0: [sdb] 30310400 512-byte logical blocks: (15.5 GB/14.5 GiB)
[ 6983.558092] sd 3:0:0:0: [sdb] Write Protect is off
[ 6983.558095] sd 3:0:0:0: [sdb] Mode Sense: 45 00 00 00
[ 6983.558314] sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn’t support DPO or FUA
[ 6983.560061] sdb: sdb1
[ 6983.563403] sd 3:0:0:0: [sdb] Attached SCSI removable disk
[ 7045.431954] wlp2s0: disassociated from a0:55:4f:27:bd:01 (Reason: 1)
[ 7049.003277] wlp2s0: authenticate with a0:55:4f:27:bd:01
[ 7049.006680] wlp2s0: send auth to a0:55:4f:27:bd:01 (try 1/3)
[ 7049.015786] wlp2s0: authenticated
[ 7049.021441] wlp2s0: associate with a0:55:4f:27:bd:01 (try 1/3)
[ 7049.038590] wlp2s0: RX AssocResp from a0:55:4f:27:bd:01 (capab=0x431 status=0 aid=140)
[ 7049.043217] wlp2s0: associated
[ 7049.063811] wlp2s0: Limiting TX power to 30 (30 – 0) dBm as advertised by a0:55:4f:27:bd:01
[ 7129.257920] usb 2-2: USB disconnect, device number 3

Since output is always large, it is advisable to use dmesg command along with grep command.
For example :

dmesg | grep "usb"

It gives output

[ 5944.925979] usb 2-1: new low-speed USB device number 2 using xhci_hcd
[ 5945.085658] usb 2-1: New USB device found, idVendor=04d9, idProduct=1702
[ 5945.085663] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 5945.085666] usb 2-1: Product: USB Keyboard
[ 5945.085669] usb 2-1: Manufacturer:
[ 5945.222536] input: USB Keyboard as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:04D9:1702.0003/input/input19
[ 5945.282554] hid-generic 0003:04D9:1702.0003: input,hidraw2: USB HID v1.10 Keyboard [ USB Keyboard] on usb-0000:00:14.0-1/input0
[ 5945.284803] input: USB Keyboard as /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.1/0003:04D9:1702.0004/input/input20
[ 5945.342340] hid-generic 0003:04D9:1702.0004: input,hidraw3: USB HID v1.10 Device [ USB Keyboard] on usb-0000:00:14.0-1/input1
[ 6981.985310] usb 2-2: new high-speed USB device number 3 using xhci_hcd
[ 6982.128179] usb 2-2: New USB device found, idVendor=0930, idProduct=6544
[ 6982.128185] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 6982.128188] usb 2-2: Product: DataTraveler 2.0
[ 6982.128190] usb 2-2: Manufacturer: Kingston
[ 6982.128193] usb 2-2: SerialNumber: C86000886407C141DA1401A2
[ 6982.253866] usb-storage 2-2:1.0: USB Mass Storage device detected
[ 6982.254035] scsi host3: usb-storage 2-2:1.0
[ 6982.254716] usbcore: registered new interface driver usb-storage
[ 6982.265103] usbcore: registered new interface driver uas
[ 7129.257920] usb 2-2: USB disconnect, device number 3

Output with options :
For example :

dmesg -t 

-t specifies output with timestamps.
Output :

usb 2-2: new high-speed USB device number 3 using xhci_hcd
usb 2-2: New USB device found, idVendor=0930, idProduct=6544
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: DataTraveler 2.0
usb 2-2: Manufacturer: Kingston
usb 2-2: SerialNumber: C86000886407C141DA1401A2
usb-storage 2-2:1.0: USB Mass Storage device detected
scsi host3: usb-storage 2-2:1.0
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver uas
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 4
sd 3:0:0:0: Attached scsi generic sg1 type 0
sd 3:0:0:0: [sdb] 30310400 512-byte logical blocks: (15.5 GB/14.5 GiB)
sd 3:0:0:0: [sdb] Write Protect is off
sd 3:0:0:0: [sdb] Mode Sense: 45 00 00 00
sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn’t support DPO or FUA
sdb: sdb1
sd 3:0:0:0: [sdb] Attached SCSI removable disk
wlp2s0: disassociated from a0:55:4f:27:bd:01 (Reason: 1)
wlp2s0: authenticate with a0:55:4f:27:bd:01
wlp2s0: send auth to a0:55:4f:27:bd:01 (try 1/3)
wlp2s0: authenticated
wlp2s0: associate with a0:55:4f:27:bd:01 (try 1/3)
wlp2s0: RX AssocResp from a0:55:4f:27:bd:01 (capab=0x431 status=0 aid=140)
wlp2s0: associated
wlp2s0: Limiting TX power to 30 (30 – 0) dBm as advertised by a0:55:4f:27:bd:01
usb 2-2: USB disconnect, device number 3

References :
1) http://www.linfo.org/dmesg.html
2) wikipedia dmesg

Mandeep Singh



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.