lan*_*oni 2 shell resolution monitors display
你如何检测aspect ratio
你的显示器?我试过:
root@malou-laptop:/home/liv# xrandr -q
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 640 x 480, current 1680 x 1050, maximum 1680 x 1050
default connected 1680x1050+0+0 0mm x 0mm
1680x1050 60.0*
1280x1024 61.0
1280x800 0.0
1024x768 61.0
800x600 61.0
640x480 60.0
Run Code Online (Sandbox Code Playgroud)
并发现您可以通过1680:1050 = 1.6 = 16:10
或通过检查维基百科上的显示分辨率列表来计算它。
但是有没有一个命令可以很好地输出这个?我已经尝试过lshw
并且hardinfo
没有运气。
你自己找到了命令,你只需要解析它。例如:
$ xrandr -q | grep -Po 'current\s*\d+\s*x\s*\d+' | awk '{print $1/$3}'
Run Code Online (Sandbox Code Playgroud)
正则表达式查找current
,然后是 0 个或多个空格字符 ( \s*
),然后是一个或多个数字 ( \d+
) \s*
,然后是x
,然后是\s*
,最后是更多的数字。在\K
简单地丢弃任何被匹配到这一点:
$ xrandr -q | grep -Po 'current\s*\K\d+\s*x\s*\d+'
1680 x 1050
Run Code Online (Sandbox Code Playgroud)
因此,您将其传递给gawk
将拆分为空白字段的内容,并打印第二个字段除以第四个字段的结果。
更好的方法是从维基百科获取列表并将其粘贴到文本文件中(确保正确复制字段之间的选项卡):
$ cat resolutions.txt
VGA 4:3 640 480 00.02 n/a
SVGA 4:3 800 600 00.17 01.03
WSVGA ~17:10 1024 600 00.31 02.25
XGA 4:3 1024 768 05.53 18.69
XGA+ 4:3 1152 864 00.87 01.55
WXGA 16:9 1280 720 01.51 01.54
WXGA 5:3 1280 768 n/a 01.54
WXGA 16:10 1280 800 04.25 12.97
SXGA– (UVGA) 4:3 1280 960 00.72 00.72
SXGA 5:4 1280 1024 10.66 07.49
HD ~16:9 1360 768 02.36 02.28
HD ~16:9 1366 768 17.19 19.14
SXGA+ 4:3 1400 1050 00.18 n/a
WXGA+ 16:10 1440 900 07.60 06.61
HD+ 16:9 1600 900 06.82 03.82
UXGA 4:3 1600 1200 00.53 n/a
WSXGA+ 16:10 1680 1050 10.26 03.66
FHD 16:9 1920 1080 25.04 05.09
WUXGA 16:10 1920 1200 03.65 01.11
QWXGA 16:9 2048 1152 00.13 n/a
WQHD 16:9 2560 1440 00.72 00.36
WQXGA 16:10 2560 1600 00.19 n/a
3:4 768 1024 n/a 01.93
16:9 1093 614 n/a 00.63
~16:9 1311 737 n/a 00.35
Other 01.29 07.25
Run Code Online (Sandbox Code Playgroud)
现在,使用该文件来获取您需要的值:
$ grep -Po 'current\s*\K\d+\s*x\s*\d+' a | sed 's/ *x */ /' |
while read x y; do
grep "$x" resolutions.txt | grep "$y" | awk -F"\t" '{print $2}';
done
16:10
Run Code Online (Sandbox Code Playgroud)
最后,把它变成一个小脚本:
#!/usr/bin/env bash
## The location of the file with the resolutions
RESOLUTIONS="$HOME/resolutions.txt"
xrandr -q | grep -Po 'current\s*\K\d+\s*x\s*\d+' | sed 's/ *x */ /' |
while read x y; do
grep "$x" "$RESOLUTIONS" | grep "$y" | awk -F"\t" '{print $2}';
done
Run Code Online (Sandbox Code Playgroud)
将脚本保存在 $PATH 中的某个位置,然后运行它以获得分辨率:
$ get_resolution.sh
16:10
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3816 次 |
最近记录: |