Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How to get a USB-drive label

by Steve_BZ (Chaplain)
on May 26, 2011 at 02:07 UTC ( #906736=perlquestion: print w/replies, xml ) Need Help??
Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I hope this is my last USB-drive-related question :) Does anyone know how to determine the label and drive capacity for a USB-drive under Linux? I looked under Device::USB and there doesn't seem to be anything and nothing else is jumping out at me from cpan.

Regards

Steve.

Replies are listed 'Best First'.
Re: How to get a USB-drive label
by NetWallah (Canon) on May 26, 2011 at 03:13 UTC
    Maybe you can parse the output of these commands, and piece the information together:
    ~$ lsusb .... Bus 001 Device 005: ID 0424:2602 Standard Microsystems Corp. USB 2.0 H +ub Bus 001 Device 010: ID 13fe:3100 Kingston Technology Company Inc. 2 GB + USB stick ... ~$mount ... /dev/sde1 on /media/0D5D-ABCE type vfat (rw,nosuid,nodev,uhelper=udisk +s,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush) ~$ ls -l /dev/disk/by-path/ total 0 drwxr-xr-x 2 root root 340 2011-05-25 19:45 ./ drwxr-xr-x 6 root root 120 2011-05-25 12:42 ../ lrwxrwxrwx 1 root root 9 2011-05-25 19:42 pci-0000:00:02.1-usb-0:2.1 +.1:1.0-scsi-0:0:0:0 -> ../../sdc lrwxrwxrwx 1 root root 9 2011-05-25 19:42 pci-0000:00:02.1-usb-0:2.1 +.1:1.0-scsi-0:0:0:1 -> ../../sdd lrwxrwxrwx 1 root root 9 2011-05-25 19:45 pci-0000:00:02.1-usb-0:5:1 +.0-scsi-0:0:0:0 -> ../../sde lrwxrwxrwx 1 root root 10 2011-05-25 19:45 pci-0000:00:02.1-usb-0:5:1 +.0-scsi-0:0:0:0-part1 -> ../../sde1 lrwxrwxrwx 1 root root 9 2011-05-25 19:42 pci-0000:00:08.0-scsi-0:0: +0:0 -> ../../sda -- SO in this case, /dev/sde1 is the partition on my 2GB kingston key, + mounted at /media/0D5D-ABCE

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Re: How to get a USB-drive label
by Khen1950fx (Canon) on May 26, 2011 at 03:46 UTC
    For me, this is the easiest way:
    #!/usr/bin/perl use strict; use warnings; system("fdisk -l /dev/sda");
Re: How to get a USB-drive label
by FunkyMonk (Chancellor) on Jul 14, 2011 at 23:25 UTC
    Just adding to the mix...

    What about parsing the output of df if you know where it's mounted

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://906736]
Approved by sundialsvc4
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2018-06-20 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (117 votes). Check out past polls.

    Notices?