Friday, October 31, 2008

11 Simple Ways To Recover Your Screen on Linux and Unix

Hey there,

If you're one of the many readers who submit a comment now and again (and even if you aren't ;), today's post is an homage to your helpful and insightful suggestions and tips. Some of you reading this right now may have emailed me with something that deserves to be posted as a comment to another post, and I can say, with great confidence, that it eventually will. I personally respond to all emails, so sometimes balancing that with work, family and more work can cause me to get a little behind. I'm still going to keep doing things this way, of course, not because I'm lazy or narrow-minded (okay, that's up for debate ;), but because I believe in actually responding to anyone who takes the time to send me a comment. And, just to clarify, this response-ethic of mine does not apply in any way shape or form to folks who write me one sentence vulgarities. If you want (or need) to hurl an insult my way, I strongly encourage it, but I probably won't write you back. Like with every other cycle, no matter who started it, someone has to end it :)

And, now, just to keep you on your toes, I'll include a hyperlink back to the original article on 9 simple ways to recover your screen in the same sentence that I let you know that this post is virtually the same material, only bigger, better and with extra sauce ;) Unless you want to read the rambling introduction (which is different in the original post), don't bother visiting the original page. All of the useful stuff from that post is included in today's version.

Once, again, a super-sized Thanks to everyone who wrote in with suggestions for this post and any other post. I truly appreciate your taking the time to write in and am almost always impressed, after a reading, with how much I don't know ;)

And, here we go again. Attribution for reader suggestions will accompany those points; otherwise, this post - from here on out - will be almost exactly the same as the last one.

Have a great weekend!

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

10. Suggested by Matthew Lenz! Here's a very simple way to get back your screen. Why does it work? I have no idea, but I tested it and it does on every machine I could try it out on :

host # cat /bin/cat

11. Suggested by James Ranks! One of these control key combinations will almost always work for you and remove the garbage from your screen (see point 9 for a link back on how to really represent control characters in Linux or Unix) :

host # ctrl-v followed by ctl-n

or

host # ctrl-v followed by ctl-o

Hopefully this little cheat sheet will come in handy at some time. You'll most likely be typing "in the dark."

Cheers,

, Mike



zcat made this comment regarding the post. It illustrates a good point: If things get too hairy, you have to know when to just bail and fix your terminal the old-fashioned way :)

I've catted plenty of binary files in the past and never needed anything
beyond 'reset' to recover from it. Perhaps I just got lucky.

But if I ever did need more than a reset, I think I would probably just
log out and back in at that point; the advantage of using a short
username like 'zcat' (and on the hosts where it's my full name I use
key-based authentication so I never have to type it)







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