{"id":5239,"date":"2018-07-03T16:33:03","date_gmt":"2018-07-03T12:33:03","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-dmesg-command\/"},"modified":"2018-07-03T16:33:03","modified_gmt":"2018-07-03T12:33:03","slug":"linux-dmesg-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-dmesg-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux dmesg Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>Do you know the Linux kernel loads several device drivers when the system boots? In fact, when your system is up and running, and you connect a hardware device, then also a corresponding device driver gets loaded. Of course, the kernel also does a lot of other stuff. What if you want to know info related to these kernel activities?<\/p>\n<p>Well, there exists a command &#8211; dubbed dmesg &#8211; that you can use if you want to access messages printed by kernel. In this tutorial, we will understand how the dmesg tool works using some easy to understand examples.<\/p>\n<h2 id=\"linux-dmesg-command\">Linux dmesg command<\/h2>\n<p>The dmesg command lets you print or control the kernel ring buffer. Following is its syntax:<\/p>\n<p class=\"command\">dmesg [options]<\/p>\n<p>And here&#8217;s how the tool&#8217;s man page explains it:<\/p>\n<pre>dmesg is used to examine or control the kernel ring buffer. The default action is to display all <br\/>messages from the kernel ring buffer.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a better idea on how the dmesg command works.<\/p>\n<h2 id=\"q-how-to-use-dmesg-command\">Q1. How to use dmesg command?<\/h2>\n<p>You can start using the dmesg command sans any command line option.<\/p>\n<p class=\"command\">dmesg<\/p>\n<p>For example, here&#8217;s a small part of output the command produced in my case:<\/p>\n<p><a class=\"fancybox\" id=\"img-dmesg-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dmesg-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples.png\" alt=\"How to use dmesg command\" width=\"500\" height=\"273\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-limit-the-output-only-to-error-and-warnings\">Q2. How to limit the output only to error and warnings?<\/h2>\n<p>If you run dmesg on your system, you&#8217;ll observe it outputs plethora of information. Depending upon what you&#8217;re looking for, you may want to filter or limit the output. For its part, dmesg offers you this ability through &#8216;levels.&#8217; Following is the complete list of levels (along with their explanation):<\/p>\n<pre>\u00a0\u00a0 emerg - system is unusable<br\/>\u00a0\u00a0 alert - action must be taken immediately<br\/>\u00a0\u00a0\u00a0 crit - critical conditions<br\/>\u00a0\u00a0\u00a0\u00a0 err - error conditions<br\/>\u00a0\u00a0\u00a0 warn - warning conditions<br\/>\u00a0 notice - normal but significant condition<br\/>\u00a0\u00a0\u00a0 info - informational<br\/>\u00a0\u00a0 debug - debug-level messages<\/pre>\n<p>So for example, if you want to limit the output to only error and warnings, you can do that in the following way:<\/p>\n<p class=\"command\">dmesg &#8211;level=err,warn<\/p>\n<p>In my case, here&#8217;s a part of output the above command produced:<\/p>\n<p><a class=\"fancybox\" id=\"img-dmesg-level\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dmesg-level.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-1.png\" alt=\"How to limit the output only to error and warnings\" width=\"500\" height=\"222\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-dmesg-produce-timestamps-in-output\">Q3. How to make dmesg produce timestamps in output?<\/h2>\n<p>Sometimes, you may want a timestamp to be associated with the messages dmesg produces. This can be done using the -T command line option, which produces human readable timestamps.<\/p>\n<p class=\"command\">dmesg -T<\/p>\n<p>Following is an example output:<\/p>\n<p><a class=\"fancybox\" id=\"img-dmesg-T\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dmesg-T.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-2.png\" alt=\"How to make dmesg produce timestamps in output\" width=\"500\" height=\"257\" title=\"\"><\/a><\/p>\n<p>So you can see a timestamp is pre-fixed with each message.<\/p>\n<h2 id=\"q-how-to-make-dmesg-display-info-specific-to-a-device\">Q4. How to make dmesg display info specific to a device?<\/h2>\n<p>Suppose you want dmesg to only display info related to eth0 interface. Here&#8217;s how you can do that:<\/p>\n<p class=\"command\">dmesg | grep -i eth0<\/p>\n<p>Following is an example output:<\/p>\n<p><a class=\"fancybox\" id=\"img-dmesg-grep\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dmesg-grep.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-3.png\" alt=\"How to make dmesg display info specific to a device\" width=\"500\" height=\"70\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-dmesg-display-only-userspace-messages\">Q5. How to make dmesg display only userspace messages?<\/h2>\n<p>If you want to limit dmesg&#8217;s output only to userspace messages, use the -u command line option.<\/p>\n<p class=\"command\">dmesg -u<\/p>\n<p><a class=\"fancybox\" id=\"img-dmesg-u\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dmesg-u.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-4.png\" alt=\"How to make dmesg display only userspace messages\" width=\"500\" height=\"203\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Agreed, dmesg is not the kind of command you&#8217;ll need everyday. But this is the tool to turn to when someone (whom you&#8217;ve asked for help on certain topic) asks you to provide kernel messages. I&#8217;ve mostly seen this case in online user forums, where experienced users ask for kernel output.<\/p>\n<p>Here, in this tutorial, we have discussed the dmesg command from beginners point of view (just to get you started). Once you are done practicing all that we&#8217;ve discussed here, head to the tool&#8217;s <a href=\"https:\/\/linux.die.net\/man\/8\/dmesg\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dmesg-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dmesg-command%2F&amp;text=Linux+dmesg+Command+Tutorial+for+Beginners+%285+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-7.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dmesg-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/07\/linux-dmesg-command-tutorial-for-beginners-5-examples-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Do you know the Linux kernel loads several device drivers when the system boots? In fact, when your system is up and running, and you connect a hardware device, then also a corresponding device driver gets loaded. Of course, the kernel also does a lot of other stuff. What if you want to know info [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-5239","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=5239"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5239\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=5239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=5239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=5239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}