Finding the /dev/input/event* path of a device from its name

I need to find a gamepad in my list of /dev/input/event* devices, and the only thing I know about it is that when I do evtest it shows up with the name G13.
The problem is every time I reboot it gets a different number. I would like to automate finding the path so I can pass it to this command in the $G13 variable:
I tried evtest | grep G13 but the problem is the evtest command doesn’t terminate on its own, it’s interactive, so my script gets stuck on a prompt.

xboxdrv --evdev $G13 --config ~/.config/xboxdrv/G13.conf &
Asked By: Poldovico


You want to set up a udev rule to provide your device with a persistent symlink. Start by running udevadm info -a /dev/input/eventXX for whichever device currently represents your gamepad.

You’ll see output like:


  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/input/input29':

Create a file /etc/udev/rules.d/90-gamepad.rules that contains:

SUBSYSTEMS=="input", ATTRS{id/product}=="c21d", ATTRS{id/vendor}=="046d", SYMLINK += "gamepad"

…replacing the values for product and vendor with the ones you see
in your output.

Save the file and run:

udevadm control -R

Unplug the gamepad and plug it back in, and you should see there is
now a symlink /dev/gamepad that points to the appropriate
/dev/input/... device.

Now you can use the device path /dev/gamepad instead of the varying
/dev/input path.

Answered By: larsks
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.