Skip to content

Instantly share code, notes, and snippets.

@devlucas
Created February 10, 2018 14:28
Show Gist options
  • Save devlucas/de6df9e5e0f2d9262f63a96b0665ad42 to your computer and use it in GitHub Desktop.
Save devlucas/de6df9e5e0f2d9262f63a96b0665ad42 to your computer and use it in GitHub Desktop.
Finds out which kernel driver is being used to serve a given device file.
#!/usr/bin/env bash
# call as: <script name> <device file path>
# example: driverfor /dev/input/mouse0
lookup_driver_in_use_for_input_device() {
device_file="$(echo $1 | awk '{gsub("/dev/", "", $1); print $1}')"
module_file="$(realpath /sys/class/$device_file/device/device/driver/module)"
echo $module_file | awk '{gsub("/sys/module/", "", $1); print $1}'
}
result="$(lookup_driver_in_use_for_input_device $1)"
echo "$result"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment