How do I find out my screen resolution from a shell script?
Solution 1
xdpyinfo | grep dimensions
will give you the total resolution, if you have multiple monitors it will be the sum of all of them. xrandr --current
will give you the resolution for each monitor.
I use this snippet to find the maximum possible resolution for rDesktop without going to full screen:
Xaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
Yaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
Output:
Xaxis = 1280
Yaxis = 1024
Minus windows decoration (more or less):
MaxRes=$(($Xaxis-5))"x"$(($Yaxis-25))
Output:
MaxRes = 1275x999
Which is the max resolution for rDesktop without going full screen.
End command:
rdesktop -u $User -P -z -5 -g $MaxRes $Host &
It works fine so far but I haven't tested thoroughly though.
Another example is for screencast with avconv
:
avconv -f x11grab -r 15 -s `xrandr --current | grep '*' | uniq | awk '{print $1}'` -i :0.0 -c:v libx264 ./output.mp4
Solution 2
You could use the xrandr -q
command. From that you can create a shell script if needed.
For more information on the command go here or type man xrandr
Solution 3
A very simple method is to read out the modes
file in the sys-directory:
cat /sys/class/graphics/*/modes
or respectively
cat /sys/class/graphics/*/virtual_size
Solution 4
Reading the Monitor Screen Data
The vesa standard provides a method of how to read the monitor screen resolution.
Extended Display Identification Data (EDID): This standard defines data formats to carry configuration information, allowing optimum use of displays.
A monitor typically supports multiple resolutions and refreshrates. Of course someone will prefer the maximum (physical) one.
To read this monitor data, try one of these solutions:
-
edid-decode
If not installed, type
sudo apt install edid-decode
Then read the
edid
fileedid-decode /sys/class/drm/card0-eDP-1/edid
-
read-edid
Install with
sudo apt install read-edid
Then read via i2c the screen monitor data and parse it
sudo get-edid | parse-edid
-
Hexdump the edid data
In case edid-tools are not installed, you can dump the
edid
hex-file, e.g.:hd /sys/class/drm/card0-eDP-1/edid
To encrypt this hex file take a look at wiki or download the edid specifications.
Solution 5
xdpyinfo
will do it, with some parsing. It gives a lot of info which you'll then have to dig the screen number, and dimensions from
Related videos on Youtube
Ykok
Updated on September 17, 2022Comments
-
Ykok over 1 year
How do I find out my screen resolution from a shell script?
-
To Kra over 8 yearsit says>
xdpyinfo: Unable to open display "".
-
CMCDragonkai about 8 yearsHow do you find out the available modes to change to?
-
c24w over 7 yearsIf you don't need to subtract for window decoration (etc), you can do this in a one-liner
rdesktop [other_args] -g $(xrandr --current | grep '*' | uniq | awk '{print $1}')
. -
Scott - Слава Україні almost 7 yearsIs there any reason for somebody to use these commands instead of the ones in Eliezer E. Vargas’s answer?
-
Scott - Слава Україні almost 7 yearsPlease edit that information into your answer.
-
Dennis Williamson almost 5 yearsIt's not the sum for multiple monitors. It's the dimensions of a bounding box which contains all the monitors.
-
SapuSeven over 4 years
xrandr --current | grep '*' | awk -v line="$SCREEN" 'NR==line{print $1}' | cut -d 'x' -f1
if you want to specify a screen (with a multi-monitor setup) (SCREEN
is 1-indexed) -
UlfR over 4 yearsIf you dont have X and
xrandr
installed,edid-decode
is a perfect tool when you want to know the supported resolutions of the connected monitor! -
Admin about 2 yearsI think this is the best answer for linux.