Posted: . At: 12:33 PM. This was 4 years ago. Post ID: 14499
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to get the desktop resolution of your monitor on Linux using the command line.


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.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.