How can I get the monitor resolution using the command line?
I would like to find a wallpaper that best suits my resolution. How can I get the resolution just by writing commands in the command line?
10 Answers 10
xdpyinfo | grep dimensions
Or to get just the resolution:
xdpyinfo | grep -oP 'dimensions:\s+\K\S+'
It works for a single monitor setup but with two monitors it sums both dimensions, for me my two screens return: 3520×1200 pixels
Good point. On the other hand, this is still useful if he’s searching for a single wallpaper to be spanned over all monitors.
@Jos, I get it this command would return 4000×1000, that is, it puts both monitors next to each other. For example, Sylvain has two monitors (1600×900 and 1920×1200) and he gets 3520×1200.
$ xrandr Screen 0: minimum 320 x 200, current 3520 x 1200, maximum 32767 x 32767 LVDS1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 310mm x 174mm 1600x900 60.0*+ 1440x900 59.9 1360x768 59.8 60.0 1152x864 60.0 1024x768 60.0 800x600 60.3 56.2 640x480 59.9 VGA1 disconnected (normal left inverted right x axis y axis) HDMI1 disconnected (normal left inverted right x axis y axis) DP1 connected primary 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm 1920x1200 60.0*+ 1920x1080 60.0 50.0 59.9 24.0 24.0 1920x1080i 60.1 50.0 60.0 1600x1200 60.0 1280x1024 75.0 60.0 1152x864 75.0 1280x720 60.0 50.0 59.9 1024x768 75.1 60.0 800x600 75.0 60.3 720x576 50.0 720x480 60.0 59.9 640x480 75.0 60.0 59.9 720x400 70.1 HDMI2 disconnected (normal left inverted right x axis y axis) HDMI3 disconnected (normal left inverted right x axis y axis) DP2 disconnected (normal left inverted right x axis y axis) DP3 disconnected (normal left inverted right x axis y axis) VIRTUAL1 disconnected (normal left inverted right x axis y axis)
Here I have two screens, the resolution are:
To get only the resolution of your primary monitor, you can also use this python oneliner:
$ python3 -c 'from gi.repository import Gdk; screen=Gdk.Screen.get_default(); \ geo = screen.get_monitor_geometry(screen.get_primary_monitor()); \ print(geo.width, "x", geo.height)' 1920 x 1200
To get the resolution of your extanded desktop (for a multi monitor setup):
$ python3 -c 'from gi.repository import Gdk; screen=Gdk.Screen.get_default(); \ print(screen.get_width(), "x", screen.get_height())' 3520 x 1200
The request was for the resolution. That is given by
xdpyinfo | grep resolution
Typically, people use resolution to mean the dimensions. The DPI is not of as much concern as the dimensions are.
Example of output on one of my machines:
LVDS connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
On a raspberry pi without X, I was able to get the screen resolution by running:
You can get your current screen’s resolution as follows:
- Get the X resolution by running:
X=$(xrandr --current | grep '*' | uniq | awk '' | cut -d 'x' -f1)
Y=$(xrandr --current | grep '*' | uniq | awk '' | cut -d 'x' -f2)
That should be possible to do like this without using awk too.
You can start by terminal your preferred website which show you your screen resolution.
firefox https://de.piliapp.com/what-is-my/screen-resolution/
You can show the webpage on your terminal too by useing https://www.brow.sh/
If you like, you can skrapping this page by terminal by include appropriate python website skrapping tools and export the output to a terminal var.
Another solution is to use xprop:
$ xprop -notype -len 16 -root _NET_DESKTOP_GEOMETRY | cut -c 25- 11520, 1080
If anyone cares, it was slightly faster on my machine than grepping xdpyinfo
Or, if you only care about width:
$ xprop -notype -len 8 -root _NET_DESKTOP_GEOMETRY | cut -c 25- 11520
Tested only on multiple displays organized via Xinerama.
For what it’s worth, when using multiple connected displays and/or offsets with TwinView then xdpyinfo will give you the resolution of the entire set of displays the way they are configured. If you require the resolution of a single monitor or a monitor connected to one of the display ports you need to use xrandr. However, even in that configuration xrandr can be unreliable and not show the resolution. See this example entry from my X windows config file:
Option "MetaModes" "DP-1: 1440x900 +0+0, DP-3: 1440x900 +1568+0, DP-5: 1440x900 +3136+0"
The xrandr output looks like this:
DVI-D-0 disconnected primary (normal left inverted right x axis y axis) HDMI-0 disconnected (normal left inverted right x axis y axis) DP-0 disconnected (normal left inverted right x axis y axis) DP-1 connected 1440x900+0+0 (normal left inverted right x axis y axis) 410mm x 256mm 1440x900 59.89*+ 1280x1024 60.02 1280x960 60.00 1280x800 59.81 1280x720 60.00 1152x864 75.00 1024x768 70.07 60.00 800x600 75.00 60.32 56.25 640x480 75.00 72.81 59.94 DP-2 disconnected (normal left inverted right x axis y axis) DP-3 connected (normal left inverted right x axis y axis) 1440x900 59.89 + 74.98 1280x1024 60.02 1280x960 60.00 1280x800 59.81 1280x720 60.00 1152x864 75.00 1024x768 70.07 60.00 800x600 75.00 60.32 56.25 640x480 75.00 72.81 59.94 DP-4 disconnected (normal left inverted right x axis y axis) DP-5 connected 1440x900+1568+0 (normal left inverted right x axis y axis) 410mm x 256mm 1440x900 59.89*+ 1280x1024 60.02 1280x960 60.00 1280x800 59.81 1280x720 60.00 1152x864 75.00 1024x768 70.07 60.00 800x600 75.00 60.32 56.25 640x480 75.00 72.81 59.94
You can see that DP-3 isn’t showing a resolution on the line that a grep for «connected» would show. So the best, most consistent, and reliable command I’ve found for identifying the resolution of any individual connected display is:
/usr/bin/xrandr --query|/usr/bin/grep -A 1 connected|grep -v connected
1440x900 59.89*+ -- 1440x900 59.89*+ 74.98 -- 1440x900 59.89*+
At that point, it’s pretty trivial to pick out the different resolutions or grep for only one port.
How to Find Linux Desktop Screen Resolution from Command Line
The continued use of a Linux operating system distribution takes its users to the dimension of unknowns where they discover limitless knowns about the computing world. The Linux operating system ecosystem and community carries individuals of all professions and skillsets.
Knowing the screen resolution of your Linux desktop environment is vital for Linux users that have invested their time and effort in fields related to graphic designs and web software development. Such users can be able to gauge their work or project expectations and delivery from this information.
Additionally, knowing the screen resolution of your Linux desktop OS can help users customize/adjust the computer’s display settings to fit certain project/work criteria.
This article will walk us through valid means of achieving the above-stated objective.
Problem Statement
We can easily determine the Linux desktop screen resolution from its GUI-based display settings. Our goal, however, is to achieve the same objective but via the Linux terminal/command-line environment.
Method 1: Using xdpyinfo Utility
The xdpyinfo utility primarily displays some general information related to how the Linux machine can be used as a server. This information can include but is not limited to vendor release number, keycode range, focus, and a number of extensions.
The xdpyinfo utility should be installed by default on your Linux OS distribution and therefore disregard the need to install its associated package via the associated Linux OS package manager.
To use the xdpyinfo utility command to retrieve the Linux desktop screen resolution, we will first execute the xdpyinfo command, pipe it to a grep command that will retrieve the dimensions aspect of its output, and finally pipe the values of the dimension to the awk command for display as Linux terminal output.
The representation of the above-discussed command execution is as follows:
$ xdpyinfo | grep "dimensions" | awk '< print $2 >'
The above command execution denotes that we are dealing with a Linux desktop screen resolution of 1366 pixels in length by 768-pixel width.
Method 2: Using the xrandr Command
The xrandr utility also comes pre-installed on almost all Linux OS distributions. Its manual page gives a detailed overview of the command and its capability.
The xrandr command belongs to the RandR extension hence its representation as X Resize, Rotate, and Reflect Extension (xrandr).
Using the xrandr command on its own should output the current screen resolution of our Linux desktop together with other viable display settings info like VGA, DP, and HDMI connection statuses.
To filter out the xrandr command to only output the current desktop screen resolution of our Linux machine, we will pipe it to a grep command with a ‘*’ command option that instructs it to retrieve the current screen resolution from the initial xrandr command. Afterward, the grep command data is piped to the awk command to print the Linux desktop’s current screen resolution.
Its implementation is shown below:
As expected, an output of 1366 pixel length by 768-pixel width is printed.