Friday, August 22, 2008

9 Simple Ways To Recover Your Screen on Linux and Unix

Hey there,

Wow, it's been a long work week. Figuratively, of course. The official version is that it was a standard 5 days ;) Tonight's post is a bit on the lighter side (both the material covered and the overall tone), as I haven't had much time to write this week. It's like my wife says; I should take some of the 1500 word rants I put down and split them up every once in a while. She's a smart lady. One of these days I'll start listening to her and take it easy on my keyboard ;)

Hopefully, today's title didn't give anyone the wrong impression. If you've gone and thrown your monitor off the balcony in a fit of rage, this post can't help you, except to offer the following advice: Go to the store and buy a buy a new one (they're much cheaper now than when you may have bought yours, which will help offset the counseling, therapy and court-ordered community service expenses ;) Then make a solemn resolution. Promise yourself that, the next time you work all night on a complex program that, even to you, barely makes any sense by the time you've accidentally deleted random chunks of it before remembering to write the buffer to disk, you will take 5 seconds, walk away, huff in a deep deep breath, count to 10 and then smash it with a brick, instead. You'll be as happy as you were last time, but you probably won't get arrested ;)

If you're a pragmatist, take a moment to reflect on the fact that (although this is a very interesting phenomena that I experience from time to time), even though you desperately want to smash your monitor into bits, it has absolutely nothing to do with the problem. For instance, I often whack my monitor on the side when Windows takes 45 minutes to boot up. I should be smacking the OS install disks, or the computer itself. If I was in full possession of my faculties (or, at least, my sense of reason) I would be kicking my own arse for expecting anything more ;)

Alas, enough pontificating. To get your weekend started off right, here are 9 ways you can, hopefully, get your terminal output back to normal if you ever cat a binary executable or do anything else that makes it all turn "Chinese" on you. Enjoy and have a safe weekend :)

Start out with the classics (NOTE: All examples will be given as command line mock-ups which end in a carriage return or enter-key press - I'm assuming you'll be typing blind)

1. See if you can clear the screen the obvious way

host # clear

2. Or maybe resetting it might help

host # reset

3. stty is also usually available on most Linux and Unix distributions, and it has a sanity check built in. Worth a shot:

host # stty sane

4. tput is also fairly common. You can use it to clear your screen, or reset it, almost like the first two options did (just from a different angle):

host # tput clear

5. and...

host # tput reset

6. Or you can use it to re-initialize the screen (gross oversimplification, but you just want your screen back, right? ;)

host # tput init

7. Finally, you can try to get it to sort out the garbage on your screen by resetting the bold and underline definitions (this makes no sense to me at all, but it works sometimes;)

host # tput sgr 0 0

8. If your shell built-in echo can do this, it's fairly easy to take this route:

host # echo -e \033c

9. And, if it doesn't (or you just can't tell because your characters are still all goofed), you can type the control characters directly:

host # echo ^[c <-- Which, if you don't want to check out the link above, translates to typing: echo and then ctl-v followed by hitting the escape key and then typing the regular letter c

Hopefully this little cheat sheet will come in handy at some time. You'll most likely be typing "in the dark." If none of these options work, I usually give in and just disconnect and re-login (It's amazing how much work goes into being lazy ;)


, Mike

Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.