My system has to auto-mount USB devices; how can I be notified when a USB device is plugged in? Where can I read more about this subject?

I would like to handle this problem via C or a shell script.

  • 1
    And what about specifically "user space" options? I want my own shell script to run A) when a drive becomes available (e.g. auto-mount) and B) when a drive is about to become unavailable (e.g. "unmount" via gvfs or a gui file manager.
    – user29020
    Apr 16, 2014 at 14:31

1 Answer 1


Udev support running external programs

KERNEL=="sdb", RUN+="/usr/bin/my_program"
  • Tip: You can use github.com/mgorny/sw-notify-send for that external program.
    – lkraav
    May 19, 2011 at 16:18
  • 3
    @lkraav: FWIW, You should be able to edit this answer...
    – Shog9
    May 19, 2011 at 19:08
  • 1
    Don't udev RUN commands run as root? Is there a way to set up a script to run from an unprivileged user space? Thanks.
    – user29020
    Apr 16, 2014 at 14:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .