26

My Slackware TTY can be broken easily by running:

cat some_binary_file

After the command, the entire TTY will no longer display readable characters but still responds to keyboard events.

Even if I logout and login again, the TTY is still broken and does not show readable characters anymore. I must restart the machine to restore normal TTY operation.

Is there a solution without restarting entire machine?

Howard
  • 2,166
  • 8
  • 27
  • 42

6 Answers6

44

Usually, running reset resets the terminal. Some key bindings from .inputrc might be lost, though.

choroba
  • 18,638
  • 4
  • 48
  • 52
  • 1
    Super simple solution that fixed my crashed tmux oh-my-zsh pane. – Shadoninja May 10 '16 at 23:14
  • 1
    This is better than the accepted answer in my opinion. When you cannot see what you are typing is easier to type `reset` and hit enter than trying to use key combinations, plus, it works 100% of the times. – Sergio Oct 25 '19 at 11:12
  • This fixed line select copy/paste not wrapping at end of terminal in Cygwin. Thanks! – Samuel Feb 02 '21 at 15:09
19

You can try the ANSI reset command:

printf "\033c"
jlliagre
  • 13,899
  • 4
  • 31
  • 48
  • this is the only one that worked on OpenBSD 5.4 – execNext Oct 01 '14 at 01:55
  • 1
    This also worked from the shell (bash) as echo -e '\033c' – Ed Randall Feb 08 '17 at 13:43
  • 3
    @EdRandall Yes. Note that "echo -e" is not supported by all shells while `printf` has the advantage of being portable so works whatever the shell, including bash. – jlliagre Feb 08 '17 at 14:53
  • I imagine that this has nothing to do with the seagull diacritic in IPA? U+033C ‹◌̼› \N{COMBINING SEAGULL BELOW} – TRiG Jul 03 '17 at 14:14
  • @TRiG Indeed. Nothing to do either with the famous [Eric Cantona's quote.](http://www.independent.co.uk/news/uk/when-the-seagulls-follow-the-trawler-it-is-because-they-think-sardines-will-be-thrown-into-the-sea-1613641.html) ;-) – jlliagre Jul 03 '17 at 14:34
19

Run echo ^v^o, that is echo and then Ctrl-v and then Ctrl-o, Enter. You will not see the Ctrl-v. It will display as echo ^O. Ctrl-v sets it into verbose mode, passing through control characters, and the Ctrl-o will reset the terminal.

Florian
  • 483
  • 1
  • 3
  • 9
  • 8
    Just a short hint: If the TTY is completely unusable or a logging console you can reset it easily from any other TTY with `echo ^v^o > /dev/ttyN` where N is the number of the terminal. – Torben Feb 24 '14 at 11:52
  • 2
    This doesn't work for me on MacOSX (10.11.6) / iTerm2 (3.0.12) / bash (4.1.2) – Ed Randall Feb 08 '17 at 13:45
  • I get a `permission denied` on Ubuntu 18.04.5 LTS – 9 Guy Dec 29 '20 at 00:50
11

My terminal didnt display any characters I typed. None of the other tricks worked. This one works:

stty sane

Worked for me. I sometimes have a terminal in an unresponsive state, but none of the other suggestions could give me the output back again. The other suggestions I tried, but didn't work:

echo ^v^o
reset
printf "\033c"

Source: https://unix.stackexchange.com/a/79686/53236

Jesper Rønn-Jensen
  • 6,910
  • 7
  • 27
  • 34
0

There are actually a few potential problems, and it might have to do with your environment. First off, as @Jesper answered, you want to do stty sane. However, you might not even be able to set up the environment correctly with that.

This is due to the difference between /bin/bash and /bin/sh. Upon opening your tty, run /bin/bash and then try stty sane. This should fix everything. Finally, I recommend adding such a thing to .bashrc

Another option would be to install a sane tty software.

0
    import subprocess
    def clear():
    if name == 'nt':
            _ = system('cls')
    else:
            _ = system('clear')
            subprocess.run(["reset"])

This works for me, my shell is /bin/bash, my enviroment is Windows 11, SWL and Python 3.8

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 24 '22 at 08:40