Search:  
Gentoo Wiki

TIP_Resetting_Your_Console

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

Keywords

ncurses, curses, reset, linux, terminfo, virtual console, termcap, tset, box, border

Introduction

After a brief discussion in the forums, I discovered there are many users who do not know about the reset command which is designed to reset your console back to its original state. This command has come in very useful after catting output from a hardware device.

reset command is also useful when curses based applications are behaving improperly. For example you may find midnight commander(mc) drawing funny borders, or say, when you are configuring linux kernel using make menuconfig, the borders are drawn as characters instead of lines, or in some extreme cases not drawn at all. One silver bullet for those (irritating) situations is the reset command.

Usage

# reset

Minor Issues

If this command does not work by just typing reset, you may need to use the command this way:

# <LF>reset<LF>

<LF> is a line feed (normally Ctrl+J) and should be used if the carriage return does not work. Also, you should note that, sometimes, the characters are not echoed back to you.

When you do not have reset

Typically a reset is performed by sending a special series of character codes to the terminal. So if you might happen to be on a system that doesn't have the reset program you can use this:

# echo ^[c

Note that the ^[c is created by typing <CTRL>-<v> followed by <ESC>, and then followed by <c>. It might be that you cannot see this and have to type blind. but after executing this, your console is back to usable again. Do not forget to prepend it with the echo command!

On a related note, clearing the screen works similarly, so if you want to clear the screen you do this using ^[[H (go to top of screen) and ^[[2J (clear the screen) which combines to ^[[H^[[2J (which you will find if you do clear > clear.txt and look at the contents of clear.txt). So clear is effectively <CTRL>-<v> <ESC> <[> <Shift>-<h> <CTRL>-<v> <ESC> <[> <2> <Shift>-<j>. Adding this code to the start of your /etc/issue will clear the screen before presenting the user with a login prompt.


Also sometimes you want to refresh the screen - in example you just changed text encoding in putty - then press CTRL+L

Automatic Console Reset on login

In case after reboot you find that applications using (n)curses are behaving in a funny way, check your /etc/rc.conf. Most probably your console font does not have UNICODE support and you might have accidentally set UNICODE. If so edit unicode support in /etc/rc.conf

UNICODE="no"

If you are still getting borders rendered as characters instead of lines and if you are using bash, put these lines in your $(HOME)/.bash_profile

# $(HOME)/.bash_profile
# only reset when logging into virtual consoles
if [ "$DISPLAY" = "" ];
then
   /usr/bin/reset;
fi

Note that the remedy is only for virtual consoles and not for X applications like xterm, rxvt or KDE konsole. In case of KDE konsole if your TERM environment variable is set to linux, then running (n)curses based applications will cause same incorrect border behaviour where border lines are rendered as characters instead of lines. If that is the case try the following command

# TERM=xterm application

Application could be any (n)curses based one like mc or make menuconfig. If you get correct borders, then it is the interaction between konsole and linux which is causing incorrect border rendering. If there are some applications you use regularly you might want to alias it in your .bashrc. For example, if you use mc, you can append the following in .bashrc

if [ "$DISPLAY" != "" ]
then
    alias mc="TERM=xterm mc";
fi;

Make a quick check that the application is working fine on your virtual console.

References

Retrieved from "http://www.gentoo-wiki.info/TIP_Resetting_Your_Console"

Last modified: Fri, 05 Sep 2008 23:12:00 +0000 Hits: 15,108