[Question]
  [
Output terminal dimensions (columns and rows) [in any two-number decimal format](https://codegolf.stackexchange.com/questions/118402/tell-me-my-screen-resolution#comment290065_118402)\*. For example, an output could be `80x25`.
---
[Inspiration](https://codegolf.stackexchange.com/q/118402/43319). [Prompt](https://codegolf.stackexchange.com/questions/118402/tell-me-my-screen-resolution?noredirect=1#comment290557_118402).  
\* Output must have both measures on a single or two consecutive lines, and there may be no more than one leading and/or trailing line of output (optionally followed by a newline). The (up to four) lines must be no longer than max(cols,1+len(str(cols))+len(str(ro‌​ws))).
  
[Answer]
# \*sh, 9
```
stty size
```
Output:
```
97 364
```
[Answer]
# 8086 machine code, 11 bytes (as a function, non-competing)
Not really competing since it doesn't have visible output. This is just showing the shortest way to find the current screen dimensions, without the boilerplate code required for printing.
```
00000000  6a 40 1f a0 84 00 40 8a  26 4a 00                 |j@....@.&J.|
0000000b
```
### How it works:
```
6a 40           |   push 0x40       ; bios data segment
1f              |   pop ds
a0 84 00        |   mov al, [0x84]  ; console rows - 1
40              |   inc ax
8a 26 4a 00     |   mov ah, [0x4a]  ; console columns
```
---
# 8086 machine code, 48 bytes (as a complete program)
```
00000000  1f bf 30 01 a0 84 04 40  e8 1a 00 b0 78 aa a0 4a  |[[email protected]](/cdn-cgi/l/email-protection)|
00000010  04 e8 11 00 8d 8d d0 fe  8d 75 ff 06 1f fd ac cd  |.........u......|
00000020  29 e2 fb cd 20 d4 0a 0c  30 aa c1 e8 08 75 f6 c3  |)... ...0....u..|
00000030
```
### How it works:
```
                |   org 0x100
                |   use16
1f              |       pop ds              ; clear ds (the stack always contains 0 on entry)
bf 30 01        |       mov di, d           ; set destination ptr
a0 84 04        |       mov al, [0x484]     ; console rows - 1
40              |       inc ax
e8 1a 00        |       call to_ascii       ; convert to ascii
b0 78           |       mov al, 'x'
aa              |       stosb
a0 4a 04        |       mov al, [0x44a]     ; console columns
e8 11 00        |       call to_ascii
8d 8d d0 fe     |       lea cx, [di-d]      ; number of characters to print
8d 75 ff        |       lea si, [di-1]      ; set source ptr
06              |       push es
1f              |       pop ds
fd              |       std                 ; reverse direction flag
ac              |   @@: lodsb               ; load (al = *si--)
cd 29           |       int 0x29            ; print al to console, bypassing stdout
e2 fb           |       loop @b             ; repeat while (--cx != 0)
cd 20           |       int 0x20            ; terminate
                |   
                |   to_ascii:
d4 0a           |       aam 10              ; ah = (al / 10), al = (al % 10)
0c 30           |       or al, 0x30         ; convert al to ascii number
aa              |       stosb               ; store (*di++ = al)
c1 e8 08        |       shr ax, 8           ; shift ah to al
75 f6           |       jnz to_ascii        ; repeat if non-zero
c3              |       ret
                |   
                |   d rb 0
```
[Answer]
# Bash, ~~22~~ 20 characters
```
echo $COLUMNS $LINES
```
Thanks to:
* [Doorknob](https://codegolf.stackexchange.com/users/3808/doorknob) for optimal output format (2 characters)
Sample run:
```
bash-4.3$ echo $COLUMNS $LINES
80 24
```
[Answer]
## xterm, 6 bytes
As you don't need specific formate, you can simply use the **`resize`** (6 character) command of `xterm`:
```
$ resize
COLUMNS=120;
LINES=31;
export COLUMNS LINES;
```
[Answer]
# sh, 20 bytes
```
tput lines;tput cols
```
.. Too obvious, maybe..
[Answer]
# [Python 3](https://docs.python.org/3/), 30 bytes
```
import os
os.get_terminal_size
```
As it does not work in TIO, an alternative is used there:
[Try it online!](https://tio.run/nexus/python3#@5@ZW5BfVKJQnFFakpnDlWYLYeilp5bEl6QW5WbmJebEF2dWpf4vKMrMK9FI09DU/A8A "Python 3 – TIO Nexus")
[Answer]
# C (linux only), ~~63~~ 61
```
short m[4];main(){ioctl(0,21523,m);printf("%dx%d",*m,m[1]);}
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 3 bytes
(Posting an answer already since this really isn't my challenge.)
`⎕SD` [**S**creen **D**imensions](http://help.dyalog.com/15.0/Content/Language/System%20Functions/sd.htm)
Sample run:
```
      ⎕SD
25 79
```
[Answer]
## C#, 59 bytes
```
using c=System.Console;_=>c.WindowWidth+"x"+c.WindowHeight;
```
Compiles to a `Func<int, string`, however, the input is not used.
[Answer]
# NodeJS, ~~50~~ ~~48~~ 46 bytes
```
> s=process.stdout;console.log(s.columns,s.rows)
80 25
```
Uses `process.stdout`s `columns` and `rows` values.
[Answer]
# Ruby, ~~41~~ ~~36~~ 21 + 13 = 34 bytes
Run with the command line flag `-rio/console`
```
p IO.console.winsize
```
This is my first Ruby golf, so tell me if there is anything I can do better.
*5 bytes saved thanks to SztupY*
*2 bytes saved thanks to manatwork*
---
This outputs height then width as a length two list.
Example output:
```
[25, 80]
```
[Answer]
# GNU Forth, 7 bytes
```
form .s
```
> 
> form – urows ucols gforth “form”
> 
> 
> The number of lines and columns in the terminal.
> 
> 
> 
## Sample Output
```
<2> 24 80
```
[Try It Online !](https://tio.run/nexus/forth-gforth#@5@WX5SroFf8/z8A)
[Answer]
# C# 94 bytes (whole app)
MetaColon's whole app answer can be shortened quite a lot:
```
using c=System.Console;class P{static void Main(){c.Write(c.WindowWidth+' '+c.WindowHeight);}}
```
[Answer]
# PowerShell + Mode, 11 Bytes?
Output may not be acceptable in current form.
the `mode` command is a default windows utility
[Meta Post](https://codegolf.meta.stackexchange.com/questions/12268/making-assumptions-about-hardware) regarding usage of `mode` without specifying `con`
```
(mode)[3,4]
```
gets the output of mode:
```
<Whitespace>
Status for device CON:
----------------------
    Lines:          3000
    Columns:        120
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      850
```
then the 4th & 5th lines (`[3,4]`) outputting:
```
PS H:\> (mode)[3,4]
    Lines:          3000
    Columns:        120
```
[Answer]
# Swift, 99 bytes
```
import Foundation;var w=winsize();ioctl(STDOUT_FILENO,UInt(TIOCGWINSZ),&w);print(w.ws_col,w.ws_row)
```
Thanks to the guys at Vapor for their [Console package](https://github.com/vapor/console/blob/master/Sources/Console/Terminal/Terminal.swift#L175).
[Answer]
# Batch, ~~25~~ ~~19~~ ~~18~~ 17 bytes
Saved 6 bytes by piping directly to the "find" command.  
Saved 1 byte thanks to [Adám / OP](https://codegolf.stackexchange.com/questions/118636/tell-me-my-console-dimensions/118681#comment290720_118681).
```
mode con|find "n"
```
This outputs the command itself since echo is on but, as [commented by OP](https://codegolf.stackexchange.com/questions/118636/tell-me-my-console-dimensions/118687#comment290692_118636), a leading line is OK.
---
Depending on your setup, it may work with only 13 bytes. However, it seems that having anything using COM ports will cause overly verbose output.
```
mode|find "n"
```
[Answer]
# C#, 85 Bytes
```
()=>System.Console.Write(System.Console.WindowWidth+"x"+System.Console.WindowHeight);
```
If you want a whole application code, we'd have **115 101 94 Bytes**:
```
using C=System.Console;class P{static void Main()=>C.Write(C.WindowWidth+"x"+C.WindowHeight);}
```
However you could mean the *Buffer* size as well, we'd have **85 Bytes** again
```
()=>System.Console.Write(System.Console.BufferWidth+"x"+System.Console.BufferHeight);
```
Or as a whole application code (obviously **115 101 94 Bytes** again):
```
using C=System.Console;class P{static void Main()=>C.Write(C.BufferWidth+"x"+C.BufferHeight);}
```
*Saved 14 Bytes in the whole application code with the help of Caius Jard*
[Answer]
# Java 8 (no libraries), Windows, 270 bytes
[Posting seperately by recommendation of Adam.](http://chat.stackexchange.com/rooms/58225/discussion-between-meq5anlrk3lqs3kfsa5hbvstwe0niu-and-adam)
```
interface B{static void main(String[] a)throws Exception{Object[]r=new java.io.BufferedReader(new java.io.InputStreamReader(Runtime.getRuntime().exec("cmd /c mode").getInputStream())).lines().toArray();System.out.print(r[3]+"\n"+r[4]);}}
```
Ungolfed:
```
interface B {
    static void main(String[] a) throws Exception {
        Object[] r = new java.io.BufferedReader(new java.io.InputStreamReader(
                Runtime.getRuntime().exec("cmd /c mode").getInputStream())
        ).lines().toArray();
        System.out.print(r[3] + "\n" + r[4]);
    }
}
```
[Answer]
# [8th](http://8th-dev.com/), ~~24~~ ~~16~~ 12 bytes
*Revised after Anders Tornblad comment.* 
```
con:size? .s
```
Returns the current size of the console in rows and columns printing stack content.
Output:
```
2  n: 000000000285e5e0 1   300
1  n: 000000000285e4c0 1   90
```
[Answer]
# Java + \*nix, 113
```
interface B{static void main(String[] a)throws Exception{new ProcessBuilder("stty","size").inheritIO().start();}}
```
Ungolfed:
```
interface B{
    static void main(String[] a)throws Exception{
        new ProcessBuilder("stty","size").inheritIO().start();
    }
}
```
`ProcessBuilder.inheritIO` causes a child process input/output to be inherited; this is the default in C with `exec`. In Java, the default is "piped." As you can see, this is way shorter than using `Runtime.getRuntime().exec()` (which is also deprecated) and constructing a `BufferedReader` through a long and convoluted call that is the result of the Java API designers' apparent unwillingness to add an overload for convenience.
[Answer]
# [Red](http://www.red-lang.org/), 19 Bytes
```
system/console/size
```
Output:
```
>> system/console/size
== 106x26
```
Can also get the screen resolution as in the previous [question](https://codegolf.stackexchange.com/a/118894/49214)
[Answer]
# Commodore 64 BASIC, 7 bytes
```
?"40x25
```
The C64 has a fixed-size text console of 40 x 25 characters. It is not necessary to query the console size, which is a good thing, as there is no way to query it.
[Answer]
# Kotlin + [Jline 2](https://github.com/jline/jline2), 58 bytes
```
{print(jline.TerminalFactory.get().run{"$width $height"})}
```
Because why not. Turns out the standard lib [actually has no way to determine console size](https://stackoverflow.com/a/1286677/7079453) so pulling in a library is required, lest you want to gold launching another process and parsing the input stream... [*would be a shame if somebody did that..*](https://codegolf.stackexchange.com/a/119012/62024)
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 7 bytes
```
termdim
```
Leaves output on the stack, as is allowed per default. Example usage:
```
λ stacked -pe "termdim"
(117 26)
```
Bonus: `termdim'x'#`` to have it `117x26`.
[Answer]
# C (linux, C89 only), ~~45~~ 41
inspired by <https://codegolf.stackexchange.com/a/118696/42186> by @dieter
```
main(m){ioctl(0,21523,&m);write(1,&m,4);}
```
this outputs the size as binary data. Not sure if this counts as "any format". You would need something extra (less, hexdump, od, ascii table) (or an esoteric terminal emulator that automatically does this for you) to make it human readable. Example usage:
```
$ ./a.out | od -sAn
     58    204
```
The terminal size is 204 cols by 58 rows.
Thanks to @Random832 for using `od` instead of `hexdump`.
]