Goofing Around with Linux Device Files

2014-12-06 00:00:00 UTC

You will often hear people say that everything in Linux is a file. That means that you can interact with physical devices no differently than if it were a file on your hard drive.

A fun way to prove this is by examining the contents of a device file on your own Linux system.

Let’s take a look at what the device file for your mouse is doing.

Try running this in your console (works in Ubuntu):

sudo cat /dev/input/mice | hexdump -C

Pretty neat, aye? Interacting with the mouse causes data to be encoded into a file on the Linux virtual filesystem. The command above will stream it into your console window for your viewing pleasure.

You could easily write a Ruby / languageXYZ script to parse these results into something useful.