Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

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.

share|improve this question
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 '14 at 14:31
up vote 4 down vote accepted

Udev support running external programs

KERNEL=="sdb", RUN+="/usr/bin/my_program"
share|improve this answer
Tip: You can use github.com/mgorny/sw-notify-send for that external program. – lkraav May 19 '11 at 16:18
@lkraav: FWIW, You should be able to edit this answer... – Shog9 May 19 '11 at 19:08
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 '14 at 14:32

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.