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.

$ xdpyinfo 
Show X Server Info
Show X Server Info

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 }'
Find Linux Desktop Screen Resolution Using xdpyinfo Command
Find Linux Desktop Screen Resolution Using xdpyinfo Command

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.

$ man xrandr

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.

$ xrandr 
Show Linux Dispay Settings
Show Linux Display Settings

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:

$ xrandr | grep '*' | awk '{ print $1 }'
Find Linux Desktop Screen Resolution Using xrandr Command
Find Linux Desktop Screen Resolution Using xrandr Command

As expected, an output of 1366 pixel length by 768-pixel width is printed.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.