Out of curiosity, when your shell character set breaks from doing something like cat /dev/urandom
is there a way to fix that in place?
3 Answers
Try one of these:
stty sane
or
reset
If both don't work, or your terminal is so messed up that you can't even enter commands, then it is best to close the terminal and start a new one.
Note that stty sane
is defined by POSIX whereas reset
is not. That means on some systems there might not be a reset
or it might do something completely different, like resetting the entire system. I have not yet encountered a system without reset
.
For more background information read "The Linux keyboard and console HOWTO" chapter "Resetting your terminal".
-
I gave you the right answer because you were the first. Sorry to the other ones. Aug 28, 2013 at 12:34
-
In general, writing random bytes to a terminal is unlikely to put it in a situation that needs stty sane to fix; that's more likely to come from a program crashing. Aug 28, 2013 at 15:13
-
stty sane
is the safe&proper way (I am weary of "reset" for the reasons I stated in comments underneath lain's answer) Aug 29, 2013 at 12:47 -
1@OlivierDulac Thank you for sharing your experience. I researched and learned that
reset
is not defined by POSIX.– LesmanaAug 30, 2013 at 17:25 -
1@Iain I do not think that @OlivierDulac is spreading FUD. The reference that
reset
is not "safe" is the fact that it is not defined by POSIX. Please stop spreading the FUD that @OlivierDulac is spreading FUD.– LesmanaAug 30, 2013 at 17:28
You can try using the reset command.
-
4You linked the man page, implicitly recommending a good RTFM. You're my hero today, thanks.– Luke404Aug 28, 2013 at 12:26
-
This works on many unixes... But some word of warning : be careful: on some systems (ie, other OSs, or maybe some other distribution of linux?) this could be initiating a system reset (I believe for example it does on some versions of solaris). Therefore reseting the system, ie forcing a reboot (without proper shutdown)... Like for any command, be careful. (This is true for other commands as well: some 'tar' for example do NOT remove "/" prefixes and therefore can overwrite sensitive files, etc. Always make sure you do know how the command you intend to use work on the system you are using.) Aug 29, 2013 at 12:46
-
1@OlivierDulac; The OP tagged his question linux so he got a linuxcentric answer although it will work on other unix systems including Solaris without issue. I worked with Solaris for 15 years! You are confusing the SPARC Open Boot Prom reset command with the userland reset(1) command. If you issue the reset at the ok prompt you're unlikely to be recovering from a corrupt terminal though.– user9517Aug 29, 2013 at 14:21
-
@lain: ah, this could be this (Open Boot prom), indeed. But still, it means on some environment "reset" is linked to resetting the host, so I prefer people (even if they are "mostly" on linux) to learn/use the "safe" "stty sane" command (which states what it does, and is not as ambiguous as "reset")... that's why I am warning readers about this. Aug 30, 2013 at 7:22
-
@OlivierDulac Solaris, CentOS, Ubuntu, OpenBSD all link reset to tset - please provide evidence for your misinformation other than your misremembering something. OBP is not a host OS so it doesn't count.– user9517Aug 30, 2013 at 7:48
cat -A
.cat
can break your character set...