dmesg (print kernel messages)

This command outputs the contents of the Linux kernel's “ring buffer”, which contains the most recent kernel messages. dmesg is often used for troubleshooting driver-related problems. For example, when a USB device is not working as it should, I run dmesg to find out if the device was identified properly by the kernel and if any error messages were generated.

Since the kernel's ring buffer is huge, dmesg's output is often passed to →tail, which filters out all but the most recent entries:

dmesg | tail -20

This will show the 20 most recent kernel messages. Another command that's often used in conjunction with dmesg is →grep, for example:

dmesg | grep -i sda

This will limit dmesg's output to lines containing the string sda. In other words, it will show you any kernel messages concerning the device sda.