List of mount points of external storage devices such as USB keyfobs and SATA external drives, from the cli

7,280

Looking in /media is a reasonable way to find hotplug block devices. You can also use lsblk to list the block devices and whether they are hotpluggable:

$ lsblk -l -p -o name,rm,hotplug,mountpoint
NAME      RM HOTPLUG MOUNTPOINT
/dev/sda   0       0 
/dev/sda1  0       0 /
/dev/sda2  0       0 [SWAP]
/dev/sda3  0       0 /home
/dev/sdc   0       1 
/dev/sdc1  0       1 
/dev/sdc2  0       1 
/dev/sdc3  0       1 /media/wd3
/dev/sdc4  0       1 
/dev/sdd   1       1 
/dev/sdd1  1       1 /media/clip

This shows that /dev/sdc is probably an external device (HOTPLUG=1), and that a partition is mounted on /media/wd3. Also there's another device on /media/clip. The RM column means removable, which sometimes applies to sd card readers, though in this case it is actually just a usb flash key.

You can also use findmnt to get from a directory name to the name of the device it is on:

$ findmnt -n -o source -T /media/wd3/my/sub/dir
/dev/sdc3
Share:
7,280

Related videos on Youtube

Hans Deragon
Author by

Hans Deragon

Software consultant. www.deragon.biz hansᴬᵀderagon.biz For the curious, my avatar is Jumpman, my very first video game I ever owned, on a Commodore 64.

Updated on September 18, 2022

Comments

  • Hans Deragon
    Hans Deragon almost 2 years

    I need to list all mount points associates to external storage devices such as USB keyfobs and SATA external drives.

    The only way I found under Ubuntu, is to call 'mount' and grep for '/media'. But I wonder if there is a better, more universal way.

    All this from the command line interface (terminal/bash).

  • Hans Deragon
    Hans Deragon about 8 years
    So this is how GUI file manager detect external devices? By looking only under /media? I ask because they seam to do a good job.
  • Hans Deragon
    Hans Deragon about 8 years
    Darn, I get this on Ubuntu 14.04 Trusty Thar LTS: # lsblk -l -o name,rm,hotplug,mountpoint lsblk: unknown column: hotplug,mountpoint Option -p is not available either. lsblk is part of the util-linux package and Ubuntu 14.04 comes with version 2.20.1-5.1ubuntu20.7. For the moment, I hesitate selecting your answer, but I am tempted since in theory, it is exactly what I am looking for. What OS are you using and more particularly, what version of lsblk?
  • meuh
    meuh about 8 years
    @HansDeragon my lsblk is version 2.26.2, on fedora 22. I think it might be finding the hotplug info from /sys but it isn't obvious where as there is no pseudo file hotplug whereas there is a /sys/block/sdd/removable file which holds 1.
  • Hans Deragon
    Hans Deragon about 8 years
    Accepted as a solution. I upgraded to Ubuntu 16.04 LTS Xenial Xerus, and it comes with util-linux 2.27.1-6ubuntu3. lsblk does the job.
  • BlackJack
    BlackJack about 6 years
    I guess nowadays they use DBus and the org.freedesktop.UDisks.EnumerateDevices method and/or listen to the org.freedesktop.UDisks.DeviceAdded signal.