I'm on FreeBSD.
I want to set console width (just console, not ssh or telnet).
I used this command:
stty cols 132
Is this work for just console or worked for all of the connections (console, ssh and telnet)?
stty does not actually re-size the terminal. It merely changes some values recorded in the line discipline. Changing the actual height and width of the terminal display proper is done with mechanisms that vary according to whether the console device is a real terminal, a kernel virtual terminal, or a user-space virtual terminal.
The console can be an honest-to-goodness real terminal, attached to a serial device. In which case, telling the terminal to re-size its display involves emitting a control sequence of some sort, down the wire to the terminal. What this control sequence is varies from terminal type to terminal type. There is no termcap capability that handily provides it, moreover.
Usually, but not always depending from what terminal one actually has at the other end of the serial line, terminals will obey the DEC private control sequences that DEC VT340s and above obey:
DECSCPP. The nosh toolset's
resizecons) command emits those:
$ resizecons 80x25
Note that most real terminals restrict what combinations of columns and rows will actually be enacted, to a fairly limited pre-defined set of terminal sizes. Classically, DEC VTs only support either 80 or 132 columns, for example.
Real terminals are the case where the line discipline's idea of terminal size has to be explicitly updated after changing the terminal's display size, by running
stty. The line discipline knows nothing about control sequences, and the terminal device itself has no way to influence the line discipline, and indeed has no knowledge that it is talking to an operating system that has such a concept as a line discipline.
The nosh toolset's user-space virtual terminals obey the same DEC private control sequences, and can be similarly adjusted with the
console-resize command. Like real terminals, they always start off in the same mode until a control sequence changes it. Unlike real terminals, but like the kernel virtual terminals that they are designed to replace, they start off in 80×25 mode rather than the 80×24 mode of many real terminals.
Similarly unlike real terminals but like kernel virtual terminals, you do not need to invoke
stty to update the line discipline after telling the terminal to change its size, because the size change operation updates the line discipline itself.
Unlike both real terminals and kernel virtual terminals, they support a much wider range of sizes that are allowed in the control sequences, from 2×2 to 65535×65535.
This brings us to kernel virtual terminals.
These are the ones provided by the terminal emulator that is built into the kernel itself. They are what you might naïvely think to be "the console" until you read the manual and realize that the console (defined as the place to which kernel diagnostic and trace output and output to
/dev/console are sent) can be a real terminal over a serial device (
comconsole), a kernel virtual terminal (
vidconsole), or nothing at all (
They are not manipulated with control sequences; rather, one opens such a terminal device and performs device-specific
ioctl() requests. Fortunately, there is a tool that wraps some of the more common
ioctl() requests, making them accessible without having to write a program of one's own.
From a login session on the kernel virtual terminal to be changed itself, or with standard input redirected from such a terminal device:
$ vidcontrol -i mode
283 (0x11b) 0x0000001f G 1280x1024x32 D 8x16 0xa0000 64k 64k 0xf1000000 5120k
$ vidcontrol MODE_283
# sysrc allscreens_flags=MODE_283
Your size choices are constrained by whether you are using the old syscons or the new vt kernel terminal emulator, and by what it knows about the display adapter that is underpinning the emulated display.
rc.conf. FreeBSD File Formats Manual.
vidcontrol. FreeBSD General Commands Manual.
sysrc. FreeBSD System Manager's Manual.
loader.conf. FreeBSD File Formats Manual.
resizecons. nosh Guide. Softwares.