30

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?

6 Answers 6

22

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.

3
  • 10
    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, 2014 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 8, 2017 at 13:45
  • 1
    I get a permission denied on Ubuntu 18.04.5 LTS
    – 9 Guy
    Dec 29, 2020 at 0:50
49

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

3
  • 1
    Super simple solution that fixed my crashed tmux oh-my-zsh pane.
    – Shadoninja
    May 10, 2016 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, 2019 at 11:12
  • This fixed line select copy/paste not wrapping at end of terminal in Cygwin. Thanks!
    – Samuel
    Feb 2, 2021 at 15:09
23

You can try the ANSI reset command:

printf "\033c"
6
  • this is the only one that worked on OpenBSD 5.4
    – execNext
    Oct 1, 2014 at 1:55
  • 1
    This also worked from the shell (bash) as echo -e '\033c'
    – Ed Randall
    Feb 8, 2017 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 8, 2017 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 3, 2017 at 14:14
  • 1
    It works in gdb too, to clear the inferior's tty: show inferior-tty then !echo -ne '\033c' > /dev/pts/XXX using XXX just shown
    – sehe
    2 days ago
12

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

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
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
  • 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.
    – Community Bot
    Oct 24, 2022 at 8:40

You must log in to answer this question.

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