I want to reliably and thoroughly identify that a usb pendrive has been connected. I'm using a reduced version¹ of Debian Buster packed in a live ISO image running in VirtualBox.

The process of scanning and identifying is made through a bash script, basically a while loop that is triggered after some user action. The script will always run in the mentioned OS above. It's not that I just want to visually and occasionaly know the information.


  • lsblk, fdisk only detect the already connected pendrives; when adding a new one, the commands won't see it.

  • lsusb, dmesg, usb-devices: the output of these commands are somewhat confusing to me, and I can't really find a distinctive pattern that lets me identify that the usb is a pendrive and not other usb device. Maybe you can point me to what pattern should I look like in any of these commands.

  • udevadm needs to be running before the pendrive is plugged. I can ask the user if they is going to plug a pendrive, tell them to wait a few seconds to plug, then run udevadm monitor. But this seems to me a little cumbersome.

The solutions I'm pondering right know are in the lines of comparing a before and after of the output of the latter commands. But alas, I really don't like that kind of approach.

As you see I have a lot of options to work with, but my question is more about to find the most optimal and reliable solution.

¹ Details of this are important? I'm not sure.

  • 5
    What do you mean by "detect"? A udev rule will detect a pendrive and can run a script when it does. This way, you can send a signal to your main process, either via kill -s or IPC. – iFreilicht Oct 17 '20 at 22:50
  • @iFreilicht Thanks! That is the right path, I forgot absolutely about udev rules. If you want to write an answer I will gladly accept it. – schrodigerscatcuriosity Oct 18 '20 at 0:34
  • Sorry, I don't have time to write a good answer right now. I suggest you take a look at this answer and this question, that should be enough to get you started. Should be enough for you to answer the question yourself :) – iFreilicht Oct 20 '20 at 8:20
  • 1
    @iFreilicht Oh I didn't have a problem to get it working, I knew about udev rules but really forgot about them, you made me remind of them :) – schrodigerscatcuriosity Oct 20 '20 at 8:23
  • I'm very curious about how exactly you got it working. Perhaps you could answer your own question? – Jaap Joris Vens Oct 20 '20 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.