Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
6  
Sure... don't do that! Also, if you think a command might produce invalid characters, use cat -A. –  jnylen Aug 28 '13 at 13:56
2  
Additionally, I've always been curious how cat can break your character set... –  crasic Aug 28 '13 at 18:46
    
cat /bin/ls often fixes this (not sure why) –  skarface Aug 28 '13 at 21:05
2  
@crasic : it sends binary to the terminal, and each terminal have ways to change font/color/etc by receiving special caracters. See the marvelous: linusakesson.net/programming/tty (aka "the TTY demystified). Depending on your TERM setting, it will react differently too (and of course, depending what bytes it receives and in what order). –  Olivier Dulac Sep 2 '13 at 10:53
    
@skarface: you probably got lucky that the binary of /bin/ls had, near the end, byte sequences that fixed the display. It will depend on the OS, the binary (ie, which version, what compile optino used, etc), and the TERM setting of your terminal... so I highly recommend you use "stty sane" instead ^^ –  Olivier Dulac Sep 2 '13 at 10:55

3 Answers 3

up vote 46 down vote accepted

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".

share|improve this answer
    
I gave you the right answer because you were the first. Sorry to the other ones. –  Pedro Montoto García Aug 28 '13 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. –  Random832 Aug 28 '13 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) –  Olivier Dulac Aug 29 '13 at 12:47
1  
@OlivierDulac Thank you for sharing your experience. I researched and learned that reset is not defined by POSIX. –  lesmana Aug 30 '13 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. –  lesmana Aug 30 '13 at 17:28

The reset command should work.

share|improve this answer

You can try using the reset command.

share|improve this answer
3  
You linked the man page, implicitly recommending a good RTFM. You're my hero today, thanks. –  Luke404 Aug 28 '13 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.) –  Olivier Dulac Aug 29 '13 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. –  Iain Aug 29 '13 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. –  Olivier Dulac Aug 30 '13 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. –  Iain Aug 30 '13 at 7:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.