42

Help! Somehow my terminal looks like this:

enter image description here

It's nearly impossible to read the text. How can I fix it without exiting the terminal?

3
  • What the heck did you did to get it that way? xD
    – Lucio
    Commented Apr 5, 2014 at 4:21
  • 4
    You can sometimes "accidentally" get this by using cat on a binary file. Commented Apr 5, 2014 at 4:22
  • 2
    I just tried to cat a binary file, was quite an experience...
    – Aditya
    Commented Apr 6, 2014 at 1:00

3 Answers 3

52

The likely cause of this problem are ANSI Escape Codes. These allow scripts to change the foreground and background color of the terminal. You can even mimic the colors of the screenshot above by running the following command:

echo -e '\E[32;46m'

To reset the terminal colors, use the following command:

tput init

According to the manpage:

    init  If the terminfo database is present and an entry for the user's
          terminal exists (see -Ttype, above), the following will occur:

          (1) if present, the terminal's initialization strings will be
              output as detailed in the terminfo(5) section on Tabs and
              Initialization,

          (2) any delays (e.g., newline) specified in the entry will be
              set in the tty driver,

          (3) tabs expansion will be turned on or off according to the
              specification in the entry, and

          (4) if tabs are not  expanded, standard  tabs  will  be  set
              (every 8 spaces).

          If an entry does not contain the information needed for any of
          the four above activities, that activity will silently be
          skipped.

This should restore your terminal to its original colors.

6
  • Could you just close it and open it again?
    – Sparhawk
    Commented Apr 5, 2014 at 4:42
  • 1
    Yes, but then all of my environment variables would be lost. Commented Apr 5, 2014 at 4:47
  • Good point. +1.
    – Sparhawk
    Commented Apr 5, 2014 at 4:47
  • 4
    reset will also work but I think it'll also reset the environment variables.
    – user249743
    Commented Apr 5, 2014 at 18:28
  • 1
    Can you please amend this answer to also cover tput setaf 7 && tput setab 0 from comments further down? It helped me when tput init did not
    – robbat2
    Commented Aug 7, 2019 at 22:57
29

You can try this command also.It will reset your terminal color.

tput sgr0

enter image description here

2
  • 3
    This one was the one that worked for me. The accepted answer did nothing, in my case.
    – Henrik
    Commented Feb 28, 2021 at 12:05
  • The accepted answer also failed for me, both echo -e '\E[32;46m'; tput init did absolutely nothing.
    – ideasman42
    Commented Jul 24, 2022 at 4:51
6

If you find your terminal in a state that none of reset, tput init, nor tput sgr0 can fix, try tput setaf 7 && tput setab 0 to force the text to white on black.

3
  • 1
    this worked on my vscode terminal when the other methods didn't
    – Vorsprung
    Commented Jun 21, 2019 at 15:11
  • Thanks! This fixed it in my terminal as well, useful still!
    – robbat2
    Commented Aug 7, 2019 at 22:57
  • 1
    sgr0 is the code that will reset everything back to normal (Whatever normal is)
    – Eric
    Commented Aug 26, 2022 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .