Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I determine the address of a pen drive in Linux?

My task is to create a file on my pen drive dynamically - as soon as I insert the pen drive, the file should be created.

share|improve this question

3 Answers 3

I would recommend using udev.

Edit: Here's a similar question which was posted in 2007. http://www.linuxquestions.org/questions/linux-software-2/how-to-detect-programatically-if-a-usb-device-is-is-plugged-in-plugged-out-524568/

share|improve this answer
    
thanks for that....i'll have a look at the link.. –  R-The_Master Dec 11 '10 at 16:43

In Ubuntu at least (meaning that the drive automounts), a drive's files can be found under /media/<drivelabel>. The drive label is either something random if you didn't set one or what you set it to.

share|improve this answer
    
Thanks for that ...But can i get the drive label dynamically ?? or if i want to set it permanently,how to do that ?? –  R-The_Master Dec 11 '10 at 16:45
    
@R-The_Master help.ubuntu.com/community/RenameUSBDrive –  digitxp Dec 11 '10 at 19:49

+1 for the UDEV Create an UDEV rule that runs a script, whenever a device with a specific UUID is inserted.

To determine the mountpoint of a device with e.g. uuid of "95738a33-589f-498d-8595-a81207f45dde", you can use the following ugly-but-working one-liner:

grep $(ls -lah /dev/disk/by-uuid/95738a33-589f-498d-8595-a81207f45dde | grep -o "sd[a-z]*[0-9]*") /etc/mtab |  awk '{print $2}'
share|improve this answer
    
I like that Idea....but the issue is that I just wanted the starting address of the drive in a variable like long x ...This is a variable in a C function....so how do i do that ?? –  R-The_Master Dec 11 '10 at 16:44

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.