Terminal Issue – How to Fix a Messed Up Terminal Screen After Resizing

bashterminal

Sometimes, a terminal screen is messed up, and when we use man ls to read the manpages, or press the UP arrow to go to previous commands in history, the screen will show characters not as the right place. (for example, treat the end of screen as some where in the middle of the screen).

The command reset is tried and it wouldn't work. One way that works is to log out or close the window, and resize the window first, and then do ssh (or close that tab, and resize the window, and then open a new tab to get a new shell).

But this way, we will lose anything that we previously did, such as starting a virtual machine console, etc. So if we don't close the shell, is there a way to fix this problem?

(this happened before right inside Fedora, and also for a Macbook ssh into a RHEL 5.4 box).

Update: I remember now how it happened in Fedora: I opened up a Terminal, and did a FreeVM to use a console of a Virtual Machine (a shell). I think it was size 80 x 25 and then after a while, I resized the Terminal to 130 x 50 approximately, and then the "inner shell" (of the VM) started to behave weird).

Best Answer

If you are using bash, check if "checkwinsize" option is activated in your session using

shopt | grep checkwinsize

If you don't get

checkwinsize    on

then activate it with

shopt -s checkwinsize

Bash documentation says for "checkwinsize" attribute :

"If set, Bash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS."

If you like the setting, you could activate checkwinsize in your ~/.bashrc.

  • To activate: shopt -s checkwinsize
  • To deactivate: shopt -u checkwinsize