Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

blkid

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?

share|improve this question
    
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 –  Nancy Smith Mar 10 '13 at 10:17
1  
Your sed -n "p" is redundant, it just prints what it gets unaltered, like cat. –  donothingsuccessfully Mar 10 '13 at 12:20

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

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.