resize
Resize a terminal window
TLDR
Resize the terminal
Print terminal size
SYNOPSIS
resize [-u|-s [rows columns]]
PARAMETERS
-u
Generate commands to set environment variables in the Bourne shell format (sh, bash, etc.).
-s [rows columns]
Specify the number of rows and columns explicitly, overriding the terminal's reported size. If only one argument is given, it's interpreted as both rows and columns.
DESCRIPTION
The resize command in Linux is used to determine the current terminal window size and generate shell commands to set the LINES and COLUMNS environment variables. These variables are used by many full-screen applications, such as vi, emacs, and curses-based programs, to properly adapt their display to the available screen real estate.
When invoked, resize attempts to ascertain the current terminal size using ioctl system calls. It then prints shell commands to standard output that can be executed to update the LINES and COLUMNS environment variables in the current shell session. These commands are specific to the shell in use (e.g., sh, csh). This ensures that applications running within that terminal inherit the correct window size information.
The command is particularly useful when working with virtual terminals, ssh sessions, or any environment where the terminal size may change dynamically after the initial login. Using resize ensures consistent and optimal display behavior across different applications and terminal sizes. Without resize, full-screen applications may not render correctly, leading to display issues and usability problems.
CAVEATS
The resize command relies on the terminal's ability to accurately report its dimensions. If the terminal emulation is not correctly configured, the results may be inaccurate. Additionally, the generated shell commands need to be executed within the current shell session to take effect; simply running resize without evaluating its output will not change the environment variables.
USAGE EXAMPLE
To update the terminal size and set environment variables, execute the following:eval `resize`
This command captures the output of resize and passes it to the eval command, which interprets and executes the generated shell commands.
HISTORY
The resize command has been part of Unix-like operating systems for a long time, evolving alongside terminal emulators and full-screen applications.
Its primary purpose has remained consistent: to dynamically adjust the terminal's environment to reflect changes in its window size, ensuring compatibility and proper rendering for interactive programs.