Weird characters appearing in the console
Such garbage may be an aftermath of a command that output binary data to your console. Usually you don't want commands to do this. Still it's possible due to a bug or some mistake. Example:
You wanted to cat file
where file
is a text file, you made a typo and run cat fild
where fild
happened to be a binary file.
In such scenario some particular byte sequences may be interpreted by your terminal emulator as control sequences or so, they will affect its later behavior.
To fix this:
- Press Ctrl+C few times in case some process is still running or you have something in the command line you typed blindly.
- Type
reset
. - Hit Enter.
From man 1 reset
:
When invoked as
reset
,tset
sets cooked and echo modes, turns off cbreak and raw modes, turns on newline translation and resets any unset special characters to their default values before doing the terminal initialization described above. This is useful after a program dies leaving a terminal in an abnormal state. Note, you may have to type<LF>reset<LF>
(the line-feed character is normally control-J) to get the terminal to work, as carriage-return may no longer work in the abnormal state. Also, the terminal will often not echo the command.
So the more foolproof version of the command seems to be:
- Type Ctrl+J
reset
Ctrl+J.
My experiences (particularly in tmux
) show in some cases reset
may not help; still it usually does.
reset
is not required by POSIX. The following commands are, each one may help:stty sane
, tput reset
.