Linux: Finding useful serial port names (i.e. NOT /dev/ttyUSB0!)

I was recently working on a project where I used USB-to-RS232 adapters to talk to some devices via serial. We started with just one device, and referenced it using /dev/ttyUSB0. Big mistake!

Later, we added another serial device. It got plugged in first, and – you guessed it – got assigned to /dev/ttyUSB0. It took a wee bit of time to figure out why the first device was spewing so much nonsense when I queried it!

Thankfully, there is a better way. The devices show up in /dev/serial/by-id/ under a unique ID hardcoded into the device. All I had to do was plug in a device, and ls /dev/serial/by-id to find out a much more useful serial port name, that would be the same whenever I used the same device. Hooray!