41
\$\begingroup\$

Output terminal dimensions (columns and rows) in any two-number decimal format*. For example, an output could be 80x25.


Inspiration. Prompt.
* 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))).

\$\endgroup\$
16
  • 2
    \$\begingroup\$ I have never seen a shorter upvoted challenge. Congrats! \$\endgroup\$
    – Mr. Xcoder
    Commented May 3, 2017 at 11:56
  • 13
    \$\begingroup\$ @Mr.Xcoder I specialise in one-liners… \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 11:57
  • \$\begingroup\$ You are about to get a degree in one-lining posts! You are indeed good, no, very good at that :))... \$\endgroup\$
    – Mr. Xcoder
    Commented May 3, 2017 at 11:58
  • \$\begingroup\$ what does 'consistent format' exactly means? \$\endgroup\$ Commented May 3, 2017 at 12:18
  • 1
    \$\begingroup\$ @FelipeNardiBatista I'll say yes for now, but revert if this leads to absurdities. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 12:24

25 Answers 25

27
\$\begingroup\$

*sh, 9

stty size

Output:

97 364
\$\endgroup\$
4
  • \$\begingroup\$ Also works in bash. \$\endgroup\$ Commented May 4, 2017 at 1:08
  • 2
    \$\begingroup\$ Or any other shell on a posix-like system. \$\endgroup\$
    – mvds
    Commented May 4, 2017 at 8:35
  • 1
    \$\begingroup\$ Given the names of some languages seen on this site, it takes longer to figure out that *sh here refers to "bash, zsh, csh, dash, etc." rather than a language whose name consists of an asterisk followed by the letters s and h :-) \$\endgroup\$ Commented May 5, 2017 at 1:34
  • \$\begingroup\$ Technically you don't even need a shell to run a program. So the sh designation doesn't really make sense anyway. \$\endgroup\$
    – mvds
    Commented May 5, 2017 at 2:24
20
\$\begingroup\$

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]|
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
\$\endgroup\$
6
  • \$\begingroup\$ I'm pretty sure a function submission would need a ret? Also, I'm not sure that you're allowed to clobber ds. This might need to be taken to Meta, as the function does work more than once, it just has unwanted side effects. \$\endgroup\$
    – user62131
    Commented May 4, 2017 at 12:38
  • \$\begingroup\$ Why does "the stack always contain 0 on entry"? I don't know of any rule that the stack gets zeroed. I guess you're talking about popping the return value and thinking that's going to be 0? Is that guaranteed for a COM binary? \$\endgroup\$
    – Cody Gray
    Commented May 5, 2017 at 3:47
  • \$\begingroup\$ @CodyGray: in a COM program, the stack initially contains a near pointer to the start of the PSP (offset 0), so RET will jump back to PSP:0, which contains a call to EXIT. stackoverflow.com/a/12593311/371250 \$\endgroup\$
    – ninjalj
    Commented May 5, 2017 at 10:58
  • \$\begingroup\$ Ah, thanks for the clarification, @ninjalj. (Great answer you linked, BTW. I'd forgotten virtually all of the details about the PSP, despite having reverse-engineered its implementation many years ago.) But if you pop that pointer off the stack without pushing it back, don't you break the RET instruction at the end of the function? \$\endgroup\$
    – Cody Gray
    Commented May 5, 2017 at 13:08
  • \$\begingroup\$ @CodyGray: you'll note that the program exits via INT 20h, not via RET, exactly because after POPing exiting via RET no longer works. \$\endgroup\$
    – ninjalj
    Commented May 6, 2017 at 10:46
18
\$\begingroup\$

Bash, 22 20 characters

echo $COLUMNS $LINES

Thanks to:

  • Doorknob for optimal output format (2 characters)

Sample run:

bash-4.3$ echo $COLUMNS $LINES
80 24
\$\endgroup\$
3
  • \$\begingroup\$ With just 1 more byte, echo $COLUMNS\x$LINES can o/p 80x24 \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 13:18
  • \$\begingroup\$ @Pandya True, but not necessary. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 13:21
  • 7
    \$\begingroup\$ Not sure if this complies with the new output format requirements, but you could just have $COLUMNS\x$LINES to output "bash: 90x50: command not found". Suppose that doesn't work with localisation though, or if that command actually exists!. \$\endgroup\$
    – Muzer
    Commented May 3, 2017 at 16:38
14
\$\begingroup\$

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;
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Nice. But you may want to write a standard header, like #xterm, 6 bytes. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 13:17
  • \$\begingroup\$ @Adám Is this type of output acceptable according to question? \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 13:22
  • 1
    \$\begingroup\$ Yes; codegolf.stackexchange.com/questions/118636/…. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 13:23
  • \$\begingroup\$ @Adám ok. Just added header :) \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 13:24
  • \$\begingroup\$ This is not xterm-specific. Note also that the output depends on your shell. \$\endgroup\$
    – celtschk
    Commented May 3, 2017 at 17:17
13
\$\begingroup\$

sh, 20 bytes

tput lines;tput cols

.. Too obvious, maybe..

\$\endgroup\$
2
  • 3
    \$\begingroup\$ tput cols; !:0 cols saves one byte in bash \$\endgroup\$
    – marcosm
    Commented May 3, 2017 at 14:12
  • \$\begingroup\$ @marcos you mean tput lines;!:0 cols, right ? \$\endgroup\$
    – dieter
    Commented May 3, 2017 at 14:20
12
\$\begingroup\$

Python 3, 30 bytes

import os
os.get_terminal_size

As it does not work in TIO, an alternative is used there:

Try it online!

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Why not just os? \$\endgroup\$ Commented May 3, 2017 at 10:59
  • 2
    \$\begingroup\$ ...it wont work on TIO, due to the operating system, so need to specify. It does work on Windows. Also import os and os. is shorter than from.... \$\endgroup\$ Commented May 3, 2017 at 11:03
  • \$\begingroup\$ I can confirm it works on Window 10 without any modifications \$\endgroup\$
    – Ferrybig
    Commented May 3, 2017 at 12:45
  • \$\begingroup\$ Works on mac too \$\endgroup\$
    – Mr. Xcoder
    Commented May 3, 2017 at 13:04
  • 1
    \$\begingroup\$ Technically Python 3.3+ \$\endgroup\$
    – matsjoyce
    Commented May 3, 2017 at 13:16
11
\$\begingroup\$

C (linux only), 63 61

short m[4];main(){ioctl(0,21523,m);printf("%dx%d",*m,m[1]);}
\$\endgroup\$
3
  • 4
    \$\begingroup\$ You could win two bytes by replacing m[0] by *m. \$\endgroup\$
    – YSC
    Commented May 3, 2017 at 16:18
  • \$\begingroup\$ You can save one byte by making m an argument of main: main(short m){ioctl(0,21523,&m);printf("%dx%d",m,(&m)[1]);} \$\endgroup\$
    – mvds
    Commented May 4, 2017 at 9:15
  • \$\begingroup\$ main(int m){ioctl(0,21523,&m);printf("%x",m);} would be 46 bytes, with sizes printed in base 16 and no separator (other than possible leading zeroes) between cols and rows. \$\endgroup\$
    – mvds
    Commented May 4, 2017 at 9:19
8
\$\begingroup\$

APL (Dyalog), 3 bytes

(Posting an answer already since this really isn't my challenge.)

⎕SDScreen Dimensions

Sample run:

      ⎕SD
25 79
\$\endgroup\$
8
\$\begingroup\$

C#, 59 bytes

using c=System.Console;_=>c.WindowWidth+"x"+c.WindowHeight;

Compiles to a Func<int, string, however, the input is not used.

\$\endgroup\$
1
  • \$\begingroup\$ Does not work; I found this returns the size the console would be if AllocConsole() were called, not the size the console standard input and output are actually connected to. Question here: stackoverflow.com/questions/35688348/… What I held back when asking the question is I was actually running on a Windows environment with stdin & stdout connected to a ssh pipeline. The win32 ssh implementation does not provide the necessary. \$\endgroup\$
    – Joshua
    Commented May 6, 2017 at 1:22
7
\$\begingroup\$

NodeJS, 50 48 46 bytes

> s=process.stdout;console.log(s.columns,s.rows)
80 25

Uses process.stdouts columns and rows values.

\$\endgroup\$
6
  • \$\begingroup\$ Thanks @ETHproductions, added console.log to output to console :) \$\endgroup\$
    – Pete TNT
    Commented May 3, 2017 at 12:47
  • \$\begingroup\$ No problem :-) The output can be in any consistent format, so I think you can save a couple bytes by doing console.log([s.columns,s.rows]). \$\endgroup\$ Commented May 3, 2017 at 12:48
  • 5
    \$\begingroup\$ 1 byte off: with(process.stdout)console.log(columns,rows) \$\endgroup\$ Commented May 4, 2017 at 5:44
  • 1
    \$\begingroup\$ And a few more bytes off (if this counts): with(process.stdout)write(columns+[rows]). Or, if it doesn't count: with(process.stdout)write(columns+' '+rows) \$\endgroup\$ Commented May 5, 2017 at 23:26
  • 1
    \$\begingroup\$ @Markasoftware Ooh, that's clever. I don't think the first one should count, though. \$\endgroup\$ Commented May 6, 2017 at 2:27
6
\$\begingroup\$

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]
\$\endgroup\$
2
  • \$\begingroup\$ you can potentially move the requires into the -r command line parameter which is only 2 extra bytes \$\endgroup\$
    – SztupY
    Commented May 3, 2017 at 14:41
  • \$\begingroup\$ No need for the single quotes around io/console, no shell will perform undesired expansion on it if left unquoted. \$\endgroup\$
    – manatwork
    Commented May 3, 2017 at 15:03
6
\$\begingroup\$

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 !

\$\endgroup\$
4
\$\begingroup\$

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);}}
\$\endgroup\$
4
\$\begingroup\$

PowerShell + Mode, 11 Bytes?

Output may not be acceptable in current form.

the mode command is a default windows utility

Meta Post 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
\$\endgroup\$
10
  • \$\begingroup\$ Save two bytes: (mode)[3,4]-replace"\D" \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 14:29
  • \$\begingroup\$ for this to work here, i need to use (mode con)[3..4] \$\endgroup\$ Commented May 3, 2017 at 14:29
  • \$\begingroup\$ Ah @FelipeNardiBatista is probably right that you need con. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 14:30
  • 1
    \$\begingroup\$ @FelipeNardiBatista is con neccessary? this gets the first lines absolutely, and I believe con is always first? i'd say a standard system will also only have one output for mode, which is what we should assume? \$\endgroup\$
    – colsw
    Commented May 3, 2017 at 14:36
  • 1
    \$\begingroup\$ @ConnorLSW It's just that my system does work fine, but your answer simply doesn't work here \$\endgroup\$ Commented May 3, 2017 at 14:51
4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

Batch, 25 19 18 17 bytes

Saved 6 bytes by piping directly to the "find" command.
Saved 1 byte thanks to Adám / OP.
Saved 1 byte thanks to comment by OP.

mode con|find "n"

This outputs the command itself since echo is on but, as commented by OP, 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"
\$\endgroup\$
13
  • \$\begingroup\$ Save a byte s:n. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 13:57
  • 1
    \$\begingroup\$ @FelipeNardiBatista Yeah, and mine says I've got 9001 lines. It's just a setting: Properties>Layout>Screen Buffer Size. \$\endgroup\$
    – Adám
    Commented May 3, 2017 at 13:58
  • \$\begingroup\$ @FelipeNardiBatista Windows console dimensions are not the same as the window dimensions. That's why scroll bars show up when you make the window smaller. Per OP, this exact solution is OK. \$\endgroup\$ Commented May 3, 2017 at 13:58
  • \$\begingroup\$ @Adám Dangit, I looked for a shorter string and don't know how I overlooked it. It's probably because I started with just mode but found that adding ` con` was shorter than looking for two different sets of characters with findstr. \$\endgroup\$ Commented May 3, 2017 at 13:59
  • \$\begingroup\$ @Adám Based on your comment, would this be valid: @mode|find "L" /i ? It returns Lines, Columns, and Keyboard Delay with 17 bytes instead of the 18 above. Do those leading / trailing lines need to be empty? \$\endgroup\$ Commented May 3, 2017 at 14:10
3
\$\begingroup\$

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

\$\endgroup\$
9
  • 1
    \$\begingroup\$ 104 bytes whole app, perhaps you can extend the logic to your other variations: using c=System.Console;class P{static void Main(){c.WriteLine(c.WindowWidth);c.Write(c.WindowHeight);}} \$\endgroup\$
    – Caius Jard
    Commented May 3, 2017 at 15:04
  • \$\begingroup\$ (I'm not sure how to golf if I have a shorter answer; do i edit yours, comment yours, or post my own?) \$\endgroup\$
    – Caius Jard
    Commented May 3, 2017 at 15:05
  • \$\begingroup\$ @CaiusJard You could post your own answer or comment an improvement and let the answerer decide if they want to incorporate it or not. \$\endgroup\$ Commented May 3, 2017 at 15:07
  • \$\begingroup\$ I wanted to, just couldn't edit my comment in time... Posted my own answer (that included it) virtually simultaneously though so I prmise I wasn't nicking your inspiration :). Not too sure whether I feel it's cheating to essentially be writing a function that returns the answer, rather than a whole app - all the other answers are pretty much a whole app, but then again CSharppPad.com will accept your "sole function" version and run it.. should look up the rules on golfing i guess \$\endgroup\$
    – Caius Jard
    Commented May 3, 2017 at 15:13
  • \$\begingroup\$ @CaiusJard Functions/methods are allowed implicitly unless explicitly disallowed in the challenge itself. Therefore, an anonymous function is fine, see my answer for a version that works well. \$\endgroup\$ Commented May 3, 2017 at 15:20
2
\$\begingroup\$

Java 8 (no libraries), Windows, 270 bytes

Posting seperately by recommendation of 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]);
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Try cmd/c mode instead of cmd /c mode. \$\endgroup\$ Commented May 5, 2017 at 0:40
  • \$\begingroup\$ Just tried, Runtime.exec() interprets that as trying to execute cmd/c resulting in CreateProcess error=2. :( \$\endgroup\$
    – F. George
    Commented May 5, 2017 at 0:49
2
\$\begingroup\$

8th, 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
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Since the question allows any output format, do you really need swap? \$\endgroup\$ Commented May 3, 2017 at 17:55
  • \$\begingroup\$ @Anders Tornblad - Thank you for your wise comment. I improved my code. \$\endgroup\$ Commented May 4, 2017 at 8:29
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ I wish ProcessBuilder would work on Windows, but the mode command outputs more than 4 lines :( \$\endgroup\$
    – F. George
    Commented May 6, 2017 at 7:30
1
\$\begingroup\$

Red, 19 Bytes

system/console/size

Output:

>> system/console/size
== 106x26

Can also get the screen resolution as in the previous question

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ This seems like cheating, although to be fair, the question (nor its inspiration) does not specifically prohibit it. \$\endgroup\$
    – Cody Gray
    Commented May 5, 2017 at 3:20
  • 2
    \$\begingroup\$ Relevant: codegolf.meta.stackexchange.com/a/1063/43319 \$\endgroup\$
    – Adám
    Commented May 5, 2017 at 5:42
1
\$\begingroup\$

Kotlin + Jline 2, 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 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..

\$\endgroup\$
8
  • \$\begingroup\$ Don't put two answers in one post. \$\endgroup\$
    – Adám
    Commented May 4, 2017 at 22:10
  • \$\begingroup\$ @Adám It's more of an afterthought, so I think it's fine. You have enough rep to edit it directly, do so if you really believe a 270b with arbitary restrictions should be a seperate answer. \$\endgroup\$
    – F. George
    Commented May 4, 2017 at 22:24
  • \$\begingroup\$ Each submission competes against other submissions in the same language. Java is inherently verbose, but yours is the shortest (and only) Java submission. Also, while I can edit your post, I cannot post a separate answer in your name. \$\endgroup\$
    – Adám
    Commented May 4, 2017 at 22:26
  • \$\begingroup\$ I was implicating that if you remove my Java answer, I will repost it myself. And while you have a point that the answer is currently the shortest Java answer, it is coded under restriction of using no external libraries. In order to address your argument, I will mark it as non-competing and code a proper Java answer later. \$\endgroup\$
    – F. George
    Commented May 4, 2017 at 22:30
  • \$\begingroup\$ Post it as Java (no libraries) and make another submission called Java with …. That will get you three upvotes from me. \$\endgroup\$
    – Adám
    Commented May 4, 2017 at 22:32
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I think hex is pushing it. All other answers use decimal, so I'm going to add this requirement to OP. Sorry. \$\endgroup\$
    – Adám
    Commented May 4, 2017 at 10:49
  • 1
    \$\begingroup\$ od -s will do it in decimal and is shorter than hexdump \$\endgroup\$
    – Random832
    Commented May 7, 2017 at 1:23
  • \$\begingroup\$ @Random832 Cool, didn't know that, +1! But this answer became invalid anyway, when the rules changed from "any format" to a very specific format (something like: base 10 in ascii in mainstream terminal emulators) \$\endgroup\$
    – mvds
    Commented May 7, 2017 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.