Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I plug in several USB drives which don't get automatically mounted. How can I find out which device file belongs to which physical device, so I can mount it for example?

I'm running Mac OS X but I rather like an answer that works on all (or at least the most popular) Unix systems. I had this problem with Linux in the past.

share|improve this question
On Linux, the answer would tend to involve udev. So you try looking around udev equivalents on OSX; this leads in particular to Alternative to udev functionality on OSX and OSX USB Device Interface Guide. – Gilles Sep 2 '11 at 23:27
On MacOSX the simplest is to identify the volumes by their labels. But Gilles has right about the perfect solution. – peterh Feb 26 '15 at 20:34
up vote 13 down vote accepted

Using udev:

You can get useful information querying udev (on systems that use it - almost all desktop-type Linuxes for sure). For instance, if you want to know which attached drive is associated with /dev/sdb, you can use:

udevadm info --query=property --name=sdb

It will show you a list of properties of that device, including the serial (ID_SERIAL_SHORT). Having that information, you can look at the output of lsusb -v and find out things like the manufacturer and product name.

A shorter path to do this would be

udevadm info --query=property --name=sdb | grep "\(MODEL_ID\|VENDOR_ID\)"

and see the line with matching $ID_VENDOR_ID:$ID_MODEL_ID in the much shorter output of lsusb.

Another useful option is udevadm monitor. Use it if you'd like know which device node is created at the point of attaching the device. So first run

 udevadm monitor --udev --subsystem-match=block

And then connect the device. You'll see the device names of the detected block devices (disks/partitions) printed at the end of each output line.

A practical example shell function:

Here's a function you can put in your .bashrc (or .zshrc) :

listusbdisks () 
    [[ "x$1" == "x-v" ]] && shift && local VERBOSE=-v
    for dsk in ${@-/dev/sd?}
        /sbin/udevadm info --query=path --name="$dsk" | grep --colour=auto -q usb || continue
        echo "===== device $dsk is:"
        ( eval $(/sbin/udevadm info --query=property --name="$dsk" | grep "\(MODEL\|VENDOR\)_ID")
          [ "$ID_VENDOR_ID:$ID_MODEL_ID" == ":" ] && echo "Unknown" || \
            lsusb $VERBOSE -d "$ID_VENDOR_ID:$ID_MODEL_ID"
        grep -q "$dsk" /proc/mounts && echo "----- DEVICE IS MOUNTED ----"

Use it like this :

  • listusbdisks - to recognize all /dev/sdx devices;
  • listusbdisks sdb or listusbdisks /dev/sdb or listusbdisks sdb sdc - to get info about certain devices only;
  • listusbdisks -v [optional devices as above] - to show verbose outputs of lsusb

[Edit]: Added some functionality like querying many devices, checking mounts and control verbosity of lsusb.

share|improve this answer
True enough as far as it goes, but not all systems use udev. – Caleb Aug 4 '11 at 20:22
@Caleb True... Actually, lsusb is also an optional program. But both are extremely common. – rozcietrzewiacz Aug 4 '11 at 20:27
@rozcietrzewiacz The question is primarily about OSX, but udev is intrinsically specific to Linux. – Gilles Aug 4 '11 at 21:39
@Gil Well, true. I've no experience with OSX, so I just updated my answer not to be misleading. – rozcietrzewiacz Aug 4 '11 at 21:52
What I generally do in such case is, I plug the device in and immediately run dmesg. But this won't be helpful if device is already plugged in and if there are more devices plugged after the first one. :) – greenmang0 Sep 2 '11 at 13:08

There is no universal answer. On Linux the simplest way is probably to just fire up the gnome disk utility and it will show all detected disks, whether they are mounted or not. From the command line, you can consult the output of blkid or udevadm info --export-db.

share|improve this answer

In Mac OS X you can try to use diskutil list.

share|improve this answer

With respect to all Unixes, I don't think this is feasible.

The usual external buses today do not use a fixed numbering scheme for their ports, like IDE did. So, the only remaining data sources for the mapping you need are the drives' manufacturer names, their serial numbers or the partitions' UIDs.

Manufacturer names are not necessarily unique on a given machine (suppose you connect two external drives from the same series - they will identify identically). Serial numbers are not "visible from the outside", as are partition UIDs.

So, about the only universal solution I can think of is to label the physical drives with the serial number and use the udevadm command given in rozcietrzewiacz's answer, if UDEV is available.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.