LINFO

The clear Command



The clear command is used to remove all previous commands and output from consoles and terminal windows in Unix-like operating systems.

A console is an all-text mode user interface that occupies the entire screen of the display device and which does not sit on top of a graphical user interface (GUI). A terminal window is a text-only window in a GUI that emulates a console and which can be opened by clicking the appropriate icon (i.e., small image) or menu item.

Clear is one of the very few commands in Unix-like operating systems that accepts neither options nor arguments (i.e., input files). That is, it is only used as follows:

clear

After the clear command has been issued, all that remains on the display screen is the command prompt in the upper left hand corner. A command prompt, also referred to as a prompt, is a short text message at the start of a line that informs the user that the system is ready for the next command, data element or other input.

Removing previous commands and output can make it easier for users to focus on and understand subsequent commands and their output. It can also be useful in preventing the next user on a system from seeing what the previous user did.

clear first looks in the environment (i.e., a set of variables that tells how to run the system) to find the type of terminal that is being used, and then it looks in the terminfo database to determine how to empty the screen of all but the command prompt on a single line. The terminfo database describes the all-text mode terminals on the system by giving a set of their capabilities, specifying how to perform screen operations and specifying initialization sequences and padding requirements.

In Unix-like operating systems there are often multiple ways of performing the same task. For example, the same result as using the clear command can be achieved in the bash shell by simultaneously pressing the CONTROL and l (lower case L) keys. A shell is a program that provides the traditional, text-only user interface in consoles and terminal windows, and bash is the default shell on Linux.

The bash shell also allows a single line to be cleared by simultaneously pressing the CONTROL and 7 (number seven) keys. In addition, everything except the current line can be removed by simultaneously pressing the CONTROL and L (upper case L) keys.






Created May 8, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.