What's the reason to add a symlink to /dev directory with udev rules?
I understand that you can write custom udev rules to create a symlink in /dev directory.
But what is the use of having a symlink in /dev?
What is the symlink linking to?
I know you can interact with regular links in the /dev directory but not understanding what a symlink does.
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0461", ATTRS{idProduct}=="4d81", SYMLINK+="myusb"
Typically it’s to give a known fixed pathname to access the device; /dev/mydevice
is fixed but depending on the order things are plugged in it might be /dev/ttyUSB0
or /dev/ttyUSB1
or /dev/ttyUSB2
or…
This can be useful for devices which can present multiple endpoints; eg I have a USB HUBZ device that presents zigbee and zwave endpoints. These rules create easy to use names
SUBSYSTEM=="tty", ATTRS{interface}=="HubZ Z-Wave Com Port", SYMLINK+="zwave"
SUBSYSTEM=="tty", ATTRS{interface}=="HubZ ZigBee Com Port", SYMLINK+="zigbee"
In my case I also have multiple printers and so the rule
#Rules for Terow printer
KERNEL=="lp*" ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5011", MODE="0666", SYMLINK+="lp_receipt"
Now I can just do cat file > /dev/lp_receipt
and it will print and I don’t need to know if it’s really /dev/usb/lp0
or /dev/usb/lp1
.
The symlimk created points to the "real" entry;
lrwxrwxrwx 1 root root 7 Sep 8 12:17 /dev/lp_receipt -> usb/lp1