{"id":6528,"date":"2018-09-04T13:44:01","date_gmt":"2018-09-04T09:44:01","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-lsblk-command\/"},"modified":"2018-09-04T13:44:01","modified_gmt":"2018-09-04T09:44:01","slug":"linux-lsblk-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-lsblk-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux lsblk Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>In Linux, block devices are special files that refer to or represent a device (which could be anything from a hard drive to a USB drive). So naturally, there are command line tools that help you with your block devices-related work. Once such utility is <strong>lsblk<\/strong>.<\/p>\n<p>In this tutorial, we will discuss this command using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples mentioned here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-lsblk-command\">Linux lsblk command<\/h2>\n<p>The lsblk command in Linux lists block devices. Following is its syntax:<\/p>\n<p class=\"command\">lsblk [options] [device&#8230;]<\/p>\n<p>And here&#8217;s how the tool&#8217;s man page explains it:<\/p>\n<pre readability=\"18\"><strong\/> lsblk\u00a0 lists\u00a0 information\u00a0 about\u00a0 all\u00a0 available or the specified block<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 devices.\u00a0 The lsblk command reads the sysfs filesystem and udev\u00a0 db\u00a0 to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gather\u00a0 information.\u00a0 If\u00a0 the udev db is not available or lsblk is com?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 piled without udev support than it tries\u00a0 to\u00a0 read\u00a0 LABELs,\u00a0 UUIDs\u00a0 and<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 filesystem\u00a0 types\u00a0 from the block device. In this case root permissions<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 are necessary.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The command prints all block devices (except RAM disks) in a\u00a0 tree-like<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 format\u00a0 by\u00a0 default.\u00a0\u00a0 Use\u00a0 lsblk --help to get a list of all available<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 columns.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The default output, as well as the default\u00a0 output\u00a0 from\u00a0 options\u00a0 like<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 --fs\u00a0 and\u00a0 --topology, is subject to change.\u00a0 So whenever possible, you<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 should avoid using default outputs in your scripts.\u00a0 Always\u00a0 explicitly<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 define\u00a0 expected columns by using --output columns-list in environments<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 where a stable output is required.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Note that lsblk might be executed in time when udev does not\u00a0 have\u00a0 all<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 information\u00a0 about recently added or modified devices yet. In this case<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 it is recommended to use udevadm settle\u00a0 before\u00a0 lsblk\u00a0 to\u00a0 synchronize<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 with udev<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a better idea on how lsblk works.<\/p>\n<h2 id=\"q-how-to-use-lsblk-command\">Q1. How to use lsblk command?<\/h2>\n<p>Basic usage is fairly simple &#8211; just execute &#8216;lsblk&#8217; sans any option.<\/p>\n<p class=\"command\">lsblk<\/p>\n<p>Following is the output this command produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsblk\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsblk.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples.png\" alt=\"How to use lsblk command\" width=\"500\" height=\"435\" title=\"\"><\/a><\/p>\n<p>The first column lists device names, followed by corresponding major and minor device numbers, whether or not the device is removable (1 in case it is), size of the device, whether or not the device is read only, type of device (disk, partition, etc), and finally the device&#8217;s mount point (if available).<\/p>\n<h2 id=\"q-how-to-make-lsblk-display-empty-devices-as-well\">Q2. How to make lsblk display empty devices as well?<\/h2>\n<p>By default, the lsblk command only displays non-empty devices. However, you can force the tool to display empty devices as well. For this, use the -a command line option.<\/p>\n<p class=\"command\">lsblk -a<\/p>\n<p>For example in my case, the above command produced the following output:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsblk-a\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsblk-a.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples-1.png\" alt=\"How to make lsblk display empty devices as well\" width=\"500\" height=\"447\" title=\"\"><\/a><\/p>\n<p>The &#8216;loop 13&#8217; row is the new addition in this case.<\/p>\n<h2 id=\"q-how-to-make-lsblk-print-size-info-in-bytes\">Q3. How to make lsblk print size info in bytes?<\/h2>\n<p>By default, lsblk prints size information in human readable form. While this good, there are times when you may need size in bytes. What&#8217;s good is that there&#8217;s an option (-b) that does this.<\/p>\n<p class=\"command\">lsblk -b<\/p>\n<p>Following is an example output:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsblk-b\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsblk-b.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples-2.png\" alt=\"How to make lsblk print size info in bytes\" width=\"500\" height=\"392\" title=\"\"><\/a><\/p>\n<p>So you can see the &#8216;Size&#8217; column now contains entries in bytes.<\/p>\n<h2 id=\"q-how-to-make-lsblk-print-zone-model-for-each-device\">Q4. How to make lsblk print zone model for each device?<\/h2>\n<p>This you can do using the -z command line option.<\/p>\n<p class=\"command\">lsblk -z<\/p>\n<p>For example, here&#8217;s the output the aforementioned command produced on my system:<\/p>\n<pre>NAME\u00a0\u00a0 ZONED<br\/>loop0\u00a0 none<br\/>loop1\u00a0 none<br\/>loop2\u00a0 none<br\/>loop3\u00a0 none<br\/>loop4\u00a0 none<br\/>loop5\u00a0 none<br\/>loop6\u00a0 none<br\/>loop7\u00a0 none<br\/>loop8\u00a0 none<br\/>loop9\u00a0 none<br\/>loop10 none<br\/>loop11 none<br\/>loop12 none<br\/>sda\u00a0\u00a0\u00a0 none<br\/>??sda1 none<br\/>??sda2 none<br\/>??sda3 none<br\/>??sda4 none<br\/>??sda5 none<br\/>??sda6 none<br\/>??sda7 none<br\/>??sda8 none<br\/>sdb\u00a0\u00a0\u00a0 none<br\/>??sdb1 none<br\/>??sdb2 none<\/pre>\n<h2 id=\"q-how-to-make-lsblk-skip-entries-for-slaves\">Q5. How to make lsblk skip entries for slaves?<\/h2>\n<p>For this, you need to use the -d command line option, which tells lsblk to not print information related to holder devices\u00a0 or\u00a0 slaves.<\/p>\n<p class=\"command\">lsblk -d<\/p>\n<p>Here&#8217;s an example output:<\/p>\n<pre>NAME\u00a0\u00a0 MAJ:MIN RM\u00a0\u00a0 SIZE RO TYPE MOUNTPOINT<br\/>loop0\u00a0\u00a0\u00a0 7:0\u00a0\u00a0\u00a0 0\u00a0\u00a0 3.3M\u00a0 1 loop \/snap\/gnome-system-monitor\/36<br\/>loop1\u00a0\u00a0\u00a0 7:1\u00a0\u00a0\u00a0 0\u00a0 86.6M\u00a0 1 loop \/snap\/core\/4486<br\/>loop2\u00a0\u00a0\u00a0 7:2\u00a0\u00a0\u00a0 0\u00a0\u00a0 140M\u00a0 1 loop \/snap\/gnome-3-26-1604\/59<br\/>loop3\u00a0\u00a0\u00a0 7:3\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 21M\u00a0 1 loop \/snap\/gnome-logs\/25<br\/>loop4\u00a0\u00a0\u00a0 7:4\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 87M\u00a0 1 loop \/snap\/core\/5145<br\/>loop5\u00a0\u00a0\u00a0 7:5\u00a0\u00a0\u00a0 0\u00a0\u00a0 1.6M\u00a0 1 loop \/snap\/gnome-calculator\/154<br\/>loop6\u00a0\u00a0\u00a0 7:6\u00a0\u00a0\u00a0 0\u00a0\u00a0 2.3M\u00a0 1 loop \/snap\/gnome-calculator\/180<br\/>loop7\u00a0\u00a0\u00a0 7:7\u00a0\u00a0\u00a0 0\u00a0 14.5M\u00a0 1 loop \/snap\/gnome-logs\/37<br\/>loop8\u00a0\u00a0\u00a0 7:8\u00a0\u00a0\u00a0 0\u00a0\u00a0 3.7M\u00a0 1 loop \/snap\/gnome-system-monitor\/51<br\/>loop9\u00a0\u00a0\u00a0 7:9\u00a0\u00a0\u00a0 0\u00a0 12.2M\u00a0 1 loop \/snap\/gnome-characters\/69<br\/>loop10\u00a0\u00a0 7:10\u00a0\u00a0 0\u00a0\u00a0\u00a0 13M\u00a0 1 loop \/snap\/gnome-characters\/103<br\/>loop11\u00a0\u00a0 7:11\u00a0\u00a0 0 140.9M\u00a0 1 loop \/snap\/gnome-3-26-1604\/70<br\/>loop12\u00a0\u00a0 7:12\u00a0\u00a0 0\u00a0 86.9M\u00a0 1 loop \/snap\/core\/4917<br\/>sda\u00a0\u00a0\u00a0\u00a0\u00a0 8:0\u00a0\u00a0\u00a0 0 931.5G\u00a0 0 disk <br\/>sdb\u00a0\u00a0\u00a0\u00a0\u00a0 8:16\u00a0\u00a0 1\u00a0 14.7G\u00a0 0 disk<\/pre>\n<p>If you compare with output produced in previous cases, you can see no slave entries are produced in output in this case.<\/p>\n<h2 id=\"q-how-to-make-lsblk-use-ascii-characters-for-tree-formatting\">Q6. How to make lsblk use ascii characters for tree formatting?<\/h2>\n<p>By default, the type of tree formatting lsblk uses may not be user friendly in many cases. For example, copy-pasting it may cause formatting issues. So if you want, you can force the tool to use ascii characters for tree formatting, something which you can do using the -i command line option.<\/p>\n<p class=\"command\">lsblk -i<\/p>\n<p>Here&#8217;s an example output:<\/p>\n<pre>NAME\u00a0\u00a0 MAJ:MIN RM\u00a0\u00a0 SIZE RO TYPE MOUNTPOINT<br\/>loop0\u00a0\u00a0\u00a0 7:0\u00a0\u00a0\u00a0 0\u00a0\u00a0 3.3M\u00a0 1 loop \/snap\/gnome-system-monitor\/36<br\/>loop1\u00a0\u00a0\u00a0 7:1\u00a0\u00a0\u00a0 0\u00a0 86.6M\u00a0 1 loop \/snap\/core\/4486<br\/>loop2\u00a0\u00a0\u00a0 7:2\u00a0\u00a0\u00a0 0\u00a0\u00a0 140M\u00a0 1 loop \/snap\/gnome-3-26-1604\/59<br\/>loop3\u00a0\u00a0\u00a0 7:3\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 21M\u00a0 1 loop \/snap\/gnome-logs\/25<br\/>loop4\u00a0\u00a0\u00a0 7:4\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 87M\u00a0 1 loop \/snap\/core\/5145<br\/>loop5\u00a0\u00a0\u00a0 7:5\u00a0\u00a0\u00a0 0\u00a0\u00a0 1.6M\u00a0 1 loop \/snap\/gnome-calculator\/154<br\/>loop6\u00a0\u00a0\u00a0 7:6\u00a0\u00a0\u00a0 0\u00a0\u00a0 2.3M\u00a0 1 loop \/snap\/gnome-calculator\/180<br\/>loop7\u00a0\u00a0\u00a0 7:7\u00a0\u00a0\u00a0 0\u00a0 14.5M\u00a0 1 loop \/snap\/gnome-logs\/37<br\/>loop8\u00a0\u00a0\u00a0 7:8\u00a0\u00a0\u00a0 0\u00a0\u00a0 3.7M\u00a0 1 loop \/snap\/gnome-system-monitor\/51<br\/>loop9\u00a0\u00a0\u00a0 7:9\u00a0\u00a0\u00a0 0\u00a0 12.2M\u00a0 1 loop \/snap\/gnome-characters\/69<br\/>loop10\u00a0\u00a0 7:10\u00a0\u00a0 0\u00a0\u00a0\u00a0 13M\u00a0 1 loop \/snap\/gnome-characters\/103<br\/>loop11\u00a0\u00a0 7:11\u00a0\u00a0 0 140.9M\u00a0 1 loop \/snap\/gnome-3-26-1604\/70<br\/>loop12\u00a0\u00a0 7:12\u00a0\u00a0 0\u00a0 86.9M\u00a0 1 loop \/snap\/core\/4917<br\/>sda\u00a0\u00a0\u00a0\u00a0\u00a0 8:0\u00a0\u00a0\u00a0 0 931.5G\u00a0 0 disk <br\/>|-sda1\u00a0\u00a0 8:1\u00a0\u00a0\u00a0 0\u00a0\u00a0 100M\u00a0 0 part <br\/>|-sda2\u00a0\u00a0 8:2\u00a0\u00a0\u00a0 0\u00a0 52.5G\u00a0 0 part <br\/>|-sda3\u00a0\u00a0 8:3\u00a0\u00a0\u00a0 0\u00a0\u00a0 293G\u00a0 0 part <br\/>|-sda4\u00a0\u00a0 8:4\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0 1K\u00a0 0 part <br\/>|-sda5\u00a0\u00a0 8:5\u00a0\u00a0\u00a0 0\u00a0 93.4G\u00a0 0 part <br\/>|-sda6\u00a0\u00a0 8:6\u00a0\u00a0\u00a0 0\u00a0\u00a0 293G\u00a0 0 part <br\/>|-sda7\u00a0\u00a0 8:7\u00a0\u00a0\u00a0 0\u00a0\u00a0 3.9G\u00a0 0 part <br\/>`-sda8\u00a0\u00a0 8:8\u00a0\u00a0\u00a0 0 195.8G\u00a0 0 part \/<br\/>sdb\u00a0\u00a0\u00a0\u00a0\u00a0 8:16\u00a0\u00a0 1\u00a0 14.7G\u00a0 0 disk <br\/>|-sdb1\u00a0\u00a0 8:17\u00a0\u00a0 1\u00a0\u00a0 200M\u00a0 0 part <br\/>`-sdb2\u00a0\u00a0 8:18\u00a0\u00a0 1\u00a0 14.5G\u00a0 0 part<\/pre>\n<p>So you can see the output (see sda entries) now contains ASCII characters in tree formatting.<\/p>\n<h2 id=\"q-how-to-make-lsblk-display-info-about-device-owner-group-and-mode\">Q7. How to make lsblk display info about device owner, group, and mode?<\/h2>\n<p>This can be achieved using the -m command line option.<\/p>\n<p class=\"command\">lsblk -m<\/p>\n<p>Here&#8217;s the output the aforementioned command produced in my case:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsblk-m\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsblk-m.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples-3.png\" alt=\"How to make lsblk display info about device owner, group, and mode\" width=\"326\" height=\"486\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-lsblk-output-select-columns\">Q8. How to make lsblk output select columns?<\/h2>\n<p>If you want, you can also direct lsblk to output only select columns, something which you can do using the -o command line option (which requires you to pass a comma separated list of columns that you want to display).<\/p>\n<p>For example:<\/p>\n<p class=\"command\">lsblk -o NAME,SIZE<\/p>\n<p>The aforementioned command produced the following output:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsblk-o\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsblk-o.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples-4.png\" alt=\"How to make lsblk output select columns\" width=\"355\" height=\"487\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>If your Linux work involves accessing information related to block devices, then lsblk is a must know command for you. Here, in this tutorial, we have discussed several command line option this tool offers. To know more about lsblk, head to its <a href=\"https:\/\/linux.die.net\/man\/8\/lsblk\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div class=\"authorbox\" readability=\"15\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples.jpg\" alt=\"Himanshu Arora\" title=\"\"> <\/p>\n<p><strong>About Himanshu Arora<\/strong><\/p>\n<p>Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu&#8217;s work has also been featured in some of world&#8217;s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.<\/p>\n<\/div>\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-lsblk-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-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-lsblk-command%2F&amp;text=Linux+lsblk+Command+Tutorial+for+Beginners+%288+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\/09\/linux-lsblk-command-tutorial-for-beginners-8-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\/09\/linux-lsblk-command-tutorial-for-beginners-8-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-lsblk-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsblk-command-tutorial-for-beginners-8-examples-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Linux, block devices are special files that refer to or represent a device (which could be anything from a hard drive to a USB drive). So naturally, there are command line tools that help you with your block devices-related work. Once such utility is lsblk. In this tutorial, we will discuss this command using [&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-6528","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6528","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=6528"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6528\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}