{"id":371738,"date":"2021-11-24T15:30:09","date_gmt":"2021-11-24T12:30:09","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/"},"modified":"2021-11-24T15:30:09","modified_gmt":"2021-11-24T12:30:09","slug":"how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/","title":{"rendered":"#How to Use lshw in Linux (With a Practical Example) \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2ec08c5a155\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2ec08c5a155\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/#What_Is_lshw\" >What Is lshw?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/#Installing_lshw-gtk\" >Installing lshw-gtk<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/#Exploring_lshw_at_the_Linux_Terminal\" >Exploring lshw at the Linux Terminal<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/#Using_a_Device_Class_to_Query_with_lshw\" >Using a Device Class to Query with lshw<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lshw-in-linux-with-a-practical-example-cloudsavvy-it\/#Wrapping_up\" >Wrapping up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Use lshw in Linux (With a Practical Example) \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"How to Use lshw in Linux (With a Practical Example)\" width=\"1400\" height=\"600\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>What if there was a command which would let you, in an easy-to-read format, view all of the hardware in your Linux system? Welcome to lshw, the great tool often overlooked even by seasoned Linux professionals.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_lshw\"><\/span>What Is <i>lshw<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>lshw<\/code>, A utility, or better tool, installed by default when you install Linux, provides you with a listing of hardware as found in your system. One can remember <code>lshw<\/code> by thinking about <code>ls<\/code> (the command which lets you list directory contents) and <code>hw<\/code> for hardware.<\/p>\n<p>While the tool has a good number of formatting options, gives detailed output for the devices it finds and can detect a solid number of device types, even seasoned Linux professionals may not have heard of it. Perhaps other tools have taken too much of a front posting on search engines and similar.<\/p>\n<p>Currently, the tool can detect DMI (x86 and IA-64), OpenFirmware device tree (PowerPC), PCI\/AGP, CPUID (x86), IDE\/ATA\/ATAPI, PCMCIA, SCSI, and USB devices.<\/p>\n<p>You can even install a graphical version of the same tool using a separate package, namely <code>lshw-gtk<\/code>. While <code>lshw<\/code> does not need to be installed and is included by Linux by default if you are interested in exploring your hardware in a GUI rather than at the command line (which this article will focus on), install <code>lshw-gtk<\/code>:<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Installing_lshw-gtk\"><\/span>Installing <i>lshw-gtk<\/i><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To install <i>lshw-gtk<\/i> on your Debian\/Apt based Linux distribution (Like Ubuntu and Mint), execute the following command in your terminal:<\/p>\n<p><code>sudo apt install lshw-gtk<\/code><\/p>\n<p>To install <i>lshw-gtk<\/i> on your RedHat\/Yum based Linux distribution (Like RHEL, Centos and Fedora), execute the following command in your terminal:<\/p>\n<p><code>sudo yum install lshw-gtk<\/code><\/p>\n<p>If you end up installing <code>lshw-gtk<\/code>, please note that there are a few oddities with this tool that may not be expected. For starters, it is recommend that you use <code>sudo lshw-gtk<\/code> at your terminal prompt to start <code>lshw-gtk<\/code> as otherwise not all hardware info may be available.<\/p>\n<p>Next, when you have started the tool, you will want to hit the <i>Refresh<\/i> button near the top as <code>lshw-gtk<\/code> does not scan hardware by default, but only on demand.<\/p>\n<p>Finally, when your hardware is scanned a few seconds later, the output seems to be missing except for a single <i>Desktop Computer<\/i> in the leftmost column. Double click this, then double click, for example <i>Motherboard<\/i> in the second column, and so on. In my own experience, I have found this particular GUI tool to be, while working, a bit limited.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14864\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/7ae5e99a.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"lshw-gtk main dialog window after scanning\" width=\"629\" height=\"408\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Do you know the difference between a crash and error and an assert? Our Asserts, Errors, and Crashes article explains the difference.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Exploring_lshw_at_the_Linux_Terminal\"><\/span>Exploring <i>lshw<\/i> at the Linux Terminal<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When you execute <code>lshw<\/code> at your Linux Terminal (which can usually be started by pressing the <code>Windows Key<\/code> + <code>T<\/code> on your keyboard, or by pressing the operating system\u2019s main icon (like the green circle in Linux Mint) and typing <i>terminal<\/i>) you will see a long and verbose output of hardware. <code>lshw<\/code> did what it was instructed to do; list all hardware.<\/p>\n<p>Let\u2019s make this work a bit better by limiting the output to what we are interested in. Firstly we should explore the hardware classes of output available to us.<\/p>\n<p>We can do this with <code>lshw -short<\/code>, which at the same time will render a shorter, much more readable overview of our hardware. Still, the output list can be 1-2 pages long, depending on your terminal settings.<\/p>\n<p>We should also at this point remember to always use <code>lshw<\/code> with <code>sudo<\/code>. This will ensure that the output will not be incomplete or inaccurate. Running <code>lshw<\/code> as <code>sudo<\/code> should be safe (famous last words!) as <code>lshw<\/code> is included by default in the Linux operating system core distribution files; one would hope it has been thoroughly evaluated.<\/p>\n<pre>sudo lshw -short | head -n6&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14865\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/2484a7df.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"lshw output in short format (using the -short option) also showing device classes, fist 6 lines of output\" width=\"483\" height=\"136\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here we requested a short list of all hardware using <code>lshw -short<\/code>, executed as the root superuser using <code>sudo<\/code>, and limited to the first six lines of output using <code>head -n6<\/code>. We <i>piped<\/i> the output from <code>lshw<\/code> to <code>head<\/code> by using a Linux pipe <code>|<\/code> which is a very handy method of post-parsing information rendered by a tool into some almost any other format required.<\/p>\n<p>Running this in VirtualBox, we see an im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely interesting bit of information: <code>lshw<\/code> is aware that the system and bus is <i>VirtualBox<\/i> based. We also see that 8GiB of memory was assigned to this VM (Virtual Machine).<\/p>\n<p>Also importantly, we can see the Class of devices being listed, which is what we will use in our next <code>lshw<\/code> example. The device Class names used in <code>lshw<\/code> are straightforward and easy to remember; there is <code>system<\/code>, <code>bus<\/code>, <code>memory<\/code>, <code>bridge<\/code>, <code>generic<\/code>, <code>multimedia<\/code>, <code>disk<\/code>, <code>input<\/code>, <code>volume<\/code>, <code>display<\/code>, <code>network<\/code>, <code>processor<\/code> and potentially a few others.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Using_a_Device_Class_to_Query_with_lshw\"><\/span>Using a Device Class to Query with <i>lshw<\/i><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that we know the device Class names, let us use the same in combination with the <code>-class<\/code> option (which can be abbreviated to <code>-C<\/code>) to query for only specific devices which we are interested in. For example, what if we had an easy way to detect if the system we were using is a virtualized machine running under VirtualBox specifically?<\/p>\n<pre>sudo lshw -short -C system&#13;\nsudo lshw -short -C system 2&gt;\/dev\/null | grep -o 'VirtualBox'&#13;\nif [ \"$(sudo lshw -short -C system 2&gt;\/dev\/null | grep -o 'VirtualBox')\" == 'VirtualBox' ]; then echo 'We are using VirtualBox!'; else echo 'This is not a VirtualBox VM!'; fi&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14866\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/a969aaab.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using lshw to establish and test whether we are running inside VirtualBox\" width=\"1000\" height=\"167\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here we executed multiple commands, each time building the command into more complexity. In the first command we simply query <code>lshw<\/code> in the same way as before, though this time with the extra <code>-C system<\/code> option to only list devices from the <code>system<\/code> class.<\/p>\n<p>After briefly scanning (not shown in the screenshot, as the output dis<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ears once the scanning is complete), the system class devices are shown, which in this case is the VirtualBox system.<\/p>\n<p>In the next command, we grep (select) for only (thanks to the <code>-o<\/code> option) the word \u2018VirtualBox\u2019. If the output does not contain \u2018VirtualBox\u2019, the command will not yield any output.<\/p>\n<p>We also added and <i>stderr<\/i> (standard error output) redirection to <code>\/dev\/null<\/code> using <code>2&gt;\/dev\/null<\/code> for the odd case where <code>sudo lshw<\/code> would render an error. This is a commonly used scripting technique when piping information from one command to another, though perhaps here there is little possibility of an error presenting itself (but not impossible).<\/p>\n<p>n the final command, we insert this code into a subshell (<code>$(...)<\/code>) and then into an <code>if<\/code> statement. Basically, we are asking the <code>Bash<\/code> interpreter to check if the output of the second command matches \u2018VirtualBox\u2019.<\/p>\n<p>If so, we can quite confidently say <i>We are using VirtualBox!<\/i>. If you execute this code on your machine, assuming you are using <code>Bash, <\/code> as your command line interpreter\/shell, and that you are not using VirtualBox, the output should be <i>This is not a VirtualBox VM!<\/i> instead.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Wrapping_up\"><\/span>Wrapping up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this article, we explored <code>lshw<\/code> and <code>lshw-gtk<\/code>, the Linux tools for obtaining detailed hardware and system information from the command line and from within a GUI on your desktop. After exploring <code>lshw<\/code> device classes, we also looked at directly using <code>lshw<\/code> information to establish whether we are running inside VirtualBox or not.<\/p>\n<p>If you enjoyed reading this article, you may like to read How to Use strace to Trace System Calls and Signals next!\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14863\/how-to-use-lshw-in-linux-with-a-practical-example\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Use lshw in Linux (With a Practical Example) \u2013 CloudSavvy IT&#8221; What if there was a command which would let you, in an easy-to-read format, view all of the hardware in your Linux system? Welcome to lshw, the great tool often overlooked even by seasoned Linux professionals. What Is lshw? lshw, A utility,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":371739,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-371738","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/371738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=371738"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/371738\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/371739"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=371738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=371738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=371738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}