dmesg command in Linux for driver messages
Last Updated :
25 Sep, 2024
dmesg command also called “driver message” or “display message” is used to examine the kernel ring buffer and print the message buffer of the 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 the kernel ring buffer are also stored in '/var/log/dmesg' file.
The dmesg command can be useful when the system encounters any problem during its start-up, so by reading the contents of dmesg command you can find out where the problem occurred(as there are many steps in the system boot-up sequence).
Syntax
dmesg [options]
Common Options for the dmesg Command
Option | Description |
---|
-C, --clear | Clears the kernel ring buffer. |
---|
-c, --read-clear | Prints the contents of the buffer and then clears it. |
---|
-D, --console-off | Disables printing of kernel messages to the console. |
---|
-E, --console-on | Enables printing of kernel messages to the console. |
---|
-F, --file <file> | Reads kernel messages from the specified file. |
---|
-h, --help | Displays help text for dmesg and its options. |
---|
-k, --kernel | Prints only kernel messages. |
---|
-t, --notime | Suppresses timestamps in the output. |
---|
-u, --userspace | Prints 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"
Practical Example: Inserting and Removing a USB Device
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"
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
Conclusion
The dmesg command is an essential tool for system administrators and developers working with Linux. It provides invaluable insights into kernel events, making it easier to troubleshoot issues related to hardware, drivers, and system startup. By using filtering options like grep, piping the output to less, or clearing the buffer when needed, you can more effectively manage and monitor kernel logs.
Similar Reads
How to Display and Set Date and Time in Linux | date Command Unlock the full potential of the date command in Linuxâa versatile tool that does more than just show the current date and time. With this command, you can set your systemâs clock, synchronize time across networks, and even calculate past or future dates for tasks like scheduling or logging. In this
8 min read
dc command in Linux with examples The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line.SyntaxThe basic syntax fo
3 min read
'dd' Command in Linux: Explained The dd command in Linux is a powerful utility for low-level data copying and conversion, primarily used for disk cloning, creating disk images, partition backups, and writing ISO files to USB drives. Mastering the dd command is essential for Linux system administrators, as it enables precise control
6 min read
declare command in Linux with Examples The built-in is a powerful built-in feature of the Bash shell. It allows users to declare and set attributes for variables and functions, enabling better control over their behavior. By understanding how to use declare, you can manage variables and functions more effectively in your shell scripts. T
2 min read
depmod command in Linux with examples depmod(Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a "Makefile"-like dependency file named modules.dep based on the symbols p
7 min read
df Command in Linux with Examples There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e. 'df' command that
9 min read
How to Compare Files Line by Line in Linux | diff Command In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process i
9 min read
diff3 command in Linux with examples diff3 command is used to compare the three files line by line. It internally uses the diff command to compare. When three files are compared then the following output may come which have their own meaning: ==== : It means all the files are different. ====1 : File 1 is different. ====2 : File 2 is di
3 min read
dir command in Linux with examples The dir command in Linux is used to list the contents of a directory, providing an overview of the files and folders within it. How is the dir command different from ls?dir command differs from the ls command in the format of listing contents that is in default listing options. By default, dir comma
5 min read
Dirname Command in Linux with Examples dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and print the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the 'dirname' command is a useful tool for e
3 min read