BASH – Fix The Display and Console Gibberish on a Linux / Unix / OS X / BSD Systems

in Categories Linux, RedHat/Fedora Linux, Shell scripting, Suse Linux, Sys admin, Tips, Troubleshooting, Ubuntu Linux, UNIX last updated December 26, 2017

Sometimes my R & D result in the weird output on the screen. For example, accidentally I run cat command over binary file – cat /sbin/*. You will be not able to access your bash/ksh/zsh based terminal. It will be full of wired character sequences that can lock down your display. These characters will hide what you type or character displayed into strange symbols. To clear gibberish all over the screen use the following method. This article describes how to really clear the terminal screen or reset terminal in Linux or Unix-like system.

The clear command

The clear command clears your screen including its scrollback buffer.
$ clear
You can press CTRL+L to clear screen too. However, clear command won’t clear the terminal screen. Use the following methods to really clear the terminal so you get a get back a good working terminal.

How to fix the display using the reset command

Here is my console with gibberish all over the screen:

Fig.01: Bash fix the display
Fig.01: Bash fix the display

To fix the display just type the reset command. It will initialization terminal again for you:
$ reset
OR
$ tput reset

If reset command failed to work type the following command to restore the session to a normal state:
$ stty sane

Press CTRL + L to clear the screen (or type the clear command):
$ clear

Use ANSI escape sequence to really clear the bash terminal

Another option is to type the following ANSI escape sequence:

clear 
echo -e "\033c"

Sample outputs from both commands:

Animated gif 01: Fix Unix Console Gibberish Command Demo
Animated gif 01: Fix Unix Console Gibberish Command Demo

Read man pages of stty and reset for more information stty(1),reset(1),bash(1)

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 11 comments/add one below):

11 comment

  1. I can’t count the number of times I’ve screwed my terminal up like this. Usually I just close the window. Thanks for the fix!

  2. This did not work for me. I guess I’m stuck killing the terminal and starting over, but I don’t understand what could go so awry that stty and reset don’t help…

  3. Hi. I know this sounds stupid. But I would like to know, Where or what subject it. I can search while looking for classes so I can learn how to run Line Print Terminals.
    I worked as a temp on a Mill for a few month operating a locomotive. while working there, I notice that came to fix the machinery got paid 200 $ hour. I want that money!!.

  4. One thing you missed: the possibility that the RET key has gone to Valhalla. Use Control-J to generate line feeds if it doesn’t work.

    Have a question? Post it on our forum!