BASH Fix Display and Console Garbage and Gibberish on a Linux / Unix / macOS

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. In other words, you will learn how to clear console garbage and gibberish without exiting the session on your Linux/Unix/macOS/BSD systems.

ADVERTISEMENTS

How to Fix Console Garbage and Gibberish on Linux and Unix

There are multiple commands to fix console gibberish or garbage. Let us see all commands and usage in details.

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

Conclusion

This page showed how to fix your console when in garbage and gibberish state. This will clear your console without exit the whole session and restart. Now that you know how to reset screen to normal mode. Read man pages of stty and reset command here for more information bash(1).

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
11 comments… add one
  • Joe Aug 9, 2006 @ 15:32

    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!

  • raj Aug 10, 2006 @ 9:21

    same here joe. I use to close bash window.

    this is great fix

  • 🐧 nixCraft Aug 10, 2006 @ 9:29

    Glad to know *this display fix* is helping all of you.

    Appreciate your feedback

  • quantumtroll Feb 11, 2008 @ 13:47

    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…

  • antonio luna Mar 10, 2009 @ 2:37

    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!!.

  • Tony Feb 23, 2013 @ 23:17

    @antonio lol …what..?

  • bonzodog Dec 9, 2014 @ 10:29

    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.

  • Dave Dec 10, 2014 @ 13:38

    Sometimes I use “tput sgr0”, but it doesn’t always work.

  • Dave Dec 10, 2014 @ 13:41

    I think the author meant “weird” instead of “wired character sequences” 😉

  • Frank Dec 10, 2014 @ 15:22

    The following command also works:
    cat /bin/ls

  • Anonymous brother Oct 29, 2016 @ 14:37

    tput sgr0

    This rules.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.