udev rules priority, disallow change by other rules with := operator

If you have ever modified udev rules, maybe you wondered, what are those numbers in the beginning of a rule name:

60-iwlwifi-led.rules**
99**-iwlwifi-led.rules

All rules files are collectively sorted and processed in lexical order.

lexical order in simple human language means that the rules are loaded according to the file names of the rules. This in turn **usually **means that larger number in the beginning of the filename gives it higher priority.

You have to keep in mind that lexical order is not the same as so called natural order (http://sourcefrog.net/projects/natsort/). So in, e.g. Konqueror with Natural sorting of items (Settings - Configure Konqueror - File Management - General), the files will appear this way:

99-iwlwifi-led.rules
999-my_own.rules

But they will be really loaded in this way:

999-my_own.rules
99-iwlwifi-led.rules

So better check the order from the console (the lower, the higher priority):

ls -l /etc/udev/rules.d/

However, there is easier way to make sure, that you rule will not be overwritten: use := operator. So even if your rule name starts with 00-, the rule statement will not be overwritten.

# Prevent an assignment being overridden by default rules - use the := operator
SUBSYSTEM=="usb", ATTR{idVendor}=="1234", ATTR{idProduct}=="1234", MODE:="0666"

Had I known it before modifying udev rules, I would save a couple of hours. Hope you will do.

Have fun!

References

udev rules doesn’t work with small number
http://superuser.com/questions/380289/udev-rules-doesnt-work-with-small-number

How to write udev rules
http://hackaday.com/2009/09/18/how-to-write-udev-rules/

Chapter 12. Dynamic Kernel Device Management with udev
https://activedoc.opensuse.org/de/node/1481

udev - dynamic device management
http://manpages.ubuntu.com/manpages/karmic/en/man7/udev.7.html