How to solve the issue that a Terminal screen is messed up? (usually after a resizing)

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

You can try Ctrl+L. It clears and/or redraws the terminal screen, depending on the program.


I had the same problem and none of the above recipes worked for me because I believe that my bash never receives the SIGWINCH signals, which are trapped by its parent process.

I finally found a solution. I added to my .bashrc:

export PROMPT_COMMAND="resize &>/dev/null ; $PROMPT_COMMAND"

Now every time I get a new prompt, my window is re-adjusted.

Thanks to UKmonkey for the PROMPT_COMMAND improvement.

Tags:

Terminal

Bash