Querying framebuffer resolution in Linux


You want to query the current resolution of a screen connected as framebuffer device (e.g. /dev/fb0).


The /sys virtual filesystem contains all information about a framebuffer device in /sys/class/graphics/<devicename>.

In order to get the size, use

cat /sys/class/graphics/fb0/virtual_size

replacing fb0 with the name of the framebuffer device to query. This will print a line like


In order to get the width/height as number, you can use these commands:

cat /sys/class/graphics/fb0/virtual_size | cut -d, -f1 # Get width
cat /sys/class/graphics/fb0/virtual_size | cut -d, -f2 # Get height