Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm running RHEL6 and I'm trying to write a udev rule that is triggered upon plugging in and removing usb devices. I created a file called 80-usb.rules in /etc/udev/rules.d/ and I gave it the following contents (so far nothing too specific, just want to test):

ACTION=="add", SUBSYSTEMS=="usb", RUN+="touch /tmp/test"

I saved the file and plugged in a USB drive to test. However, the file /tmp/test was not created.

I figure my udev rule should match my USB drive, since I can run udevadm info on the USB drive and at least one of the parent devices has the attribute SUBSYSTEMS=="usb".

Why might the udev rule not get triggered?

I tried to run udevadm test --action=add /path/to/device and it is clear that the .rules file that I wrote is being processed and that my rules are being matched. Here are a few relevant lines from the output:

parse_file: reading '/etc/udev/rules.d/80-usb.rules' as rules file
udev_rules_apply_to_event: RUN '/bin/touch /tmp/test' /etc/udev/rules.d/80-usb.rules:1
udevadm_test: run: '/bin/touch /tmp/test'

But still, /tmp/test does not exist. I am so confused. Clearly this rule is being matched and the rules are being applied. So why doesn't the command specified by RUN execute?

share|improve this question
Have you restarted udev after adding the 80-usb.rules file? systemctl restart udev.service –  drs Apr 23 '13 at 2:08
Have you tried making a script that executes the touch command and setting RUN to the path to the script? –  drs Apr 23 '13 at 2:18
The rule might have write permissions to write in /, but if you are not sure about that, at least while experimenting you should touch /tmp/udevfile –  Anthon Apr 23 '13 at 4:11
Thanks for the help guys, but none of your suggestions got me closer to a solution, unfortunately. udev isn't actually a service on my machine (udev-post is, but restarting that won't and doesn't help any). Writing to /tmp/ is a good idea though. I don't know why I wasn't writing there before. Brain fart, I guess. –  jayhendren Apr 23 '13 at 15:59
@drs Udev monitors the /etc/udev directory, you don't need to notify it when you've changed or added a rule file unless you've put a symbolic link there to a file that's outside /etc/udev. –  Gilles Apr 24 '13 at 1:29

2 Answers 2

at first add this script file to /lib/udev/touch.sh

vim /lib/udev/touch.sh

in that file write:

touch /tmp/test

make it executable

chmod +x /lib/udev/touch.sh

and change your file to:

ACTION=="add", SUBSYSTEMS=="usb", RUN+="/lib/udev/touch.sh"

reload your udev rules

udevadm control --reload-rules

it's read your /lib/udev/rules.d/* again

share|improve this answer
it just can run the script not a command –  mohammad Nov 6 '13 at 13:43

The problem is /tmp is mounted read-only when udev rules are run during startup. Try touching /dev/test instead.

share|improve this answer
This is not the problem. I stated that the rule should be run on attach/detach of USB devices, not at startup. –  jayhendren Dec 8 '14 at 20:03

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.