Getting information about your desktop resolution with the Linux command line is very easy to do.
This one-liner will print the current desktop resolution. This could be used in a script that will then do something with the output.
jason@jason-desktop:~/Videos$ xrandr | awk '{if(NR==5) print $0}' | awk '{print $1}' 3440x1440 |
Another way is by using xdpyinfo. This will print just the values we need for the resolution.
jason@jason-desktop:~/Videos$ xdpyinfo | awk '/dimensions/{print $2}' 3440x1440 |
To split this output by the “x” delimiter, use this command. This will print just the first value of the desktop resolution.
jason@jason-desktop:~/Videos$ xrandr | awk '{if(NR==5) print $0}' | awk '{print $1}' | cut -d'x' -f1 3440 |
This is to get the second value.
jason@jason-desktop:~/Videos$ xrandr | awk '{if(NR==5) print $0}' | awk '{print $1}' | cut -d'x' -f2 1440 |
This is a very useful way to get the desktop resolution for use in a script. Have fun with these commands. They should be very useful indeed.