Skip to content

Instantly share code, notes, and snippets.

@somian
Last active December 22, 2015 03:39
Show Gist options
  • Save somian/6411774 to your computer and use it in GitHub Desktop.
Save somian/6411774 to your computer and use it in GitHub Desktop.
shell pipeline to get a suffiently safe filename from a disk volume LABEL as a mount point (directory name) to mount a hotplugged device.
blkid -s TYPE|egrep vfat |
cut -d \: -f 1|
xargs /sbin/blkid -c value|
xargs perl -MFile::Util="" \
-e '$it=File::Util->new();' \
-e 'print for map{/LABEL=([^=]+)(?=[[:space:]][[:upper:]]+[=])*/;' \
-e '($1 ? do{($_=$it->escape_filename($1))=~s{[[:space:]]}{_}g and qq[/media/byLABELISH/$_\n]}' \
-e ' : q[])} grep {LABEL} @ARGV'
@somian
Copy link
Author

somian commented Sep 2, 2013

I purchased a USB hard disk storage device which had been formatted with a fat32 filesystem labelled "SP PHD U3". (Silicon Power).

We get a mount point that is like: /media/byLABELISH/SP_PHD_U3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment