{"id":243,"date":"2014-03-25T20:45:32","date_gmt":"2014-03-25T20:45:32","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=243"},"modified":"2020-03-05T22:53:49","modified_gmt":"2020-03-06T04:53:49","slug":"finding-a-drives-name-in-linux-from-the-command-line","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/finding-a-drives-name-in-linux-from-the-command-line\/","title":{"rendered":"Finding a Drives Name in Linux From the Command Line"},"content":{"rendered":"<p>There are a few different ways to find out a drives(sdcard, usb drive, external hard drive) name.<\/p>\n<p><strong>dmesg command<br \/><\/strong><\/p>\n<p>One way to do it is to look at dmesg. Insert your drive and then run the command. It displays a lot of info, what we are interested in is the end which should say something about your drive.<\/p>\n<pre>dmesg<\/pre>\n<pre>[ 4443.109976] mmc0: new high speed SDHC card at address aaaa\n[ 4443.111857] mmcblk0: mmc0:aaaa SU04G 3.69 GiB \n[ 4443.120836]  mmcblk0: p1 p2\n[ 4453.045338] EXT4-fs (mmcblk0p2): recovery complete\n[ 4453.086165] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)\n[ 4453.086184] SELinux: initialized (dev mmcblk0p2, type ext4), uses xattr<\/pre>\n<p>This tells us that the device is mmcblk0. The &#8220;p2&#8221; at the end is the partition number.<\/p>\n<h2>df Command<\/h2>\n<p>Another way to do it is to run the df command.<br \/>Run the below command without your drive plugged in.<\/p>\n<pre>df -h<\/pre>\n<p>it&#8217;ll return something like this<\/p>\n<pre>Filesystem               Size  Used Avail Use% Mounted on\n\/dev\/mapper\/fedora-root   50G   12G   36G  24% \/\ndevtmpfs                 1.9G     0  1.9G   0% \/dev\ntmpfs                    1.9G  600K  1.9G   1% \/dev\/shm\ntmpfs                    1.9G  1.0M  1.9G   1% \/run\ntmpfs                    1.9G     0  1.9G   0% \/sys\/fs\/cgroup\ntmpfs                    1.9G   28K  1.9G   1% \/tmp\n\/dev\/sdb1                477M  115M  333M  26% \/boot\n\/dev\/mapper\/fedora-home   76G   45G   23G  87% \/home<\/pre>\n<p>The above command returns all the partitions that are mounted on your computer.<br \/>Now mount your drive and run the command again, it should show your drive at the bottom.<\/p>\n<pre>[me@fedora ~]$ df -h\nFilesystem               Size  Used Avail Use% Mounted on\n\/dev\/mapper\/fedora-root   50G   12G   36G  24% \/\ndevtmpfs                 1.9G     0  1.9G   0% \/dev\ntmpfs                    1.9G  600K  1.9G   1% \/dev\/shm\ntmpfs                    1.9G  1.1M  1.9G   1% \/run\ntmpfs                    1.9G     0  1.9G   0% \/sys\/fs\/cgroup\ntmpfs                    1.9G   28K  1.9G   1% \/tmp\n\/dev\/sdb1                477M  115M  333M  26% \/boot\n\/dev\/mapper\/fedora-home   76G   45G   23G  87% \/home\n\/dev\/mmcblk0p2           3.6G  2.3G  1.1G  69% \/run\/media\/me\/fc522c75-9sws<\/pre>\n<p>You can see that the bottom one &#8220;\/dev\/mmcblk0p2 &#8221; is the partition of the drive you just plugged in.<\/p>\n<h2>Using fdisk<\/h2>\n<p>You can also use fdisk.<\/p>\n<pre>sudo fdisk -l<\/pre>\n<p>It will return something similar to the following.<\/p>\n<pre>Disk \/dev\/mapper\/fedora-home: 78.8 GiB, 191931351040 bytes, 374865920 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 4096 bytes\nI\/O size (minimum\/optimal): 4096 bytes \/ 4096 bytes\n\nDisk \/dev\/mmcblk0: 3.7 GiB, 3965190144 bytes, 7744512 sectors<\/pre>\n<p>The bottom section is the drive &#8220;mmcblk0&#8221;.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Using lsblk<\/h2>\n\n\n\n<p>lsblk is another cool tool to list drives and partions.  When run with the -p option it shows the path to the drive and partition.<\/p>\n\n\n\n<p>Example output of what you may get with &#8220;lsblk -p&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">admin@localhost:~$ lsblk -p\nNAME                              MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT\n\/dev\/nvme1n1                      259:0    0   450G  0 disk  \n\u251c\u2500\/dev\/nvme1n1p1                  259:1    0   499M  0 part  \n\u251c\u2500\/dev\/nvme1n1p2                  259:2    0   100M  0 part  \n\u251c\u2500\/dev\/nvme1n1p3                  259:3    0    16M  0 part  \n\u2514\u2500\/dev\/nvme1n1p4                  259:4    0 449.3G  0 part  \n\/dev\/nvme0n1                      259:5    0   477G  0 disk  \n \u251c\u2500\/dev\/nvme0n1p1                  259:6    0   512M  0 part  \/boot\/efi\n \u251c\u2500\/dev\/nvme0n1p2                  259:7    0   732M  0 part  \/boot\n \u2514\u2500\/dev\/nvme0n1p3                  259:8    0   400G  0 part  \n   \u2514\u2500\/dev\/mapper\/vg-root           253:1    0   391G  0 lvm   \/\n   \u2514\u2500\/dev\/mapper\/vg-swap_1         253:2    0   7.9G  0 lvm   [SWAP]\nadmin@localhost:~$ <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are a few different ways to find out a drives(sdcard, usb drive, external hard drive) name. dmesg command One way to do it is to look at dmesg. Insert your drive and then run the command. It displays a &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/finding-a-drives-name-in-linux-from-the-command-line\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[88,89,98,86,87,85,7,90,99,59,58],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-command-line","category-linux","tag-df","tag-dmesg","tag-drive-name","tag-external-hard-drive","tag-fdisk","tag-find-drive","tag-linux-2","tag-partition","tag-sd-card","tag-thumb-drive","tag-usb-drive"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":10,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":3080,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/243\/revisions\/3080"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}