Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I would recommend using udev.

Edit: Here's a similar question which was posted in 2007.

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 – 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 how do i do that ?? – R-The_Master Dec 11 '10 at 16:44

Your Answer


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.