I want to mount my USB to a mount point which holds the UUID name. But I don't know how to express this in a command line!

Can someone help me how to do it?

I have searched and found that I have to run:


then a command which searches for a USB flash or hard disk drive, then something like

blkid | tail -n 1 | cut -f4 -d' '

but tail is wrong because I don't know the number of USB I have!

Is there a way to tell it to just get me the lines with USB type?

  • here's the answer . I found it my self by trial and error: sudo blkid | tr -s ' ' | grep 'TYPE="vfat"' | cut -f4 -d'"' | sed -n "p" sed ! can't under stand it :S Mar 10 '13 at 10:17
  • 1
    Your sed -n "p" is redundant, it just prints what it gets unaltered, like cat. Mar 10 '13 at 12:20

Reading the man page shows you can use options to get what you want:

blkid -t TYPE=vfat -sUUID

gives (for me):

/dev/sdb: UUID="50CA-8C03"

You can extract the UUID with cut -d'"' -f2:

blkid -t TYPE=vfat -sUUID | cut -d'"' -f2

The blkid options are preferable because a USB drive can have e.g. a label which would give a different output of with plain blkid invocation.

EDIT: further reading of the man page shows blkid can do what you want on its own:

blkid -t TYPE=vfat -sUUID -ovalue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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