| 1 |
.\"*************************************************************************** |
| 2 |
.\" Copyright 2018-2024,2025 Thomas E. Dickey * |
| 3 |
.\" Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
| 4 |
.\" * |
| 5 |
.\" Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 |
.\" copy of this software and associated documentation files (the * |
| 7 |
.\" "Software"), to deal in the Software without restriction, including * |
| 8 |
.\" without limitation the rights to use, copy, modify, merge, publish, * |
| 9 |
.\" distribute, distribute with modifications, sublicense, and/or sell * |
| 10 |
.\" copies of the Software, and to permit persons to whom the Software is * |
| 11 |
.\" furnished to do so, subject to the following conditions: * |
| 12 |
.\" * |
| 13 |
.\" The above copyright notice and this permission notice shall be included * |
| 14 |
.\" in all copies or substantial portions of the Software. * |
| 15 |
.\" * |
| 16 |
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 |
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 |
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 |
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 |
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 |
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 |
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 |
.\" * |
| 24 |
.\" Except as contained in this notice, the name(s) of the above copyright * |
| 25 |
.\" holders shall not be used in advertising or otherwise to promote the * |
| 26 |
.\" sale, use or other dealings in this Software without prior written * |
| 27 |
.\" authorization. * |
| 28 |
.\"*************************************************************************** |
| 29 |
.\" |
| 30 |
.\" $Id: clear.1,v 1.53 2025/04/05 21:56:26 tom Exp $ |
| 31 |
.TH clear 1 2025-04-05 "ncurses 6.6" "User commands" |
| 32 |
.ie \n(.g \{\ |
| 33 |
.ds `` \(lq |
| 34 |
.ds '' \(rq |
| 35 |
.ds ' \(aq |
| 36 |
.\} |
| 37 |
.el \{\ |
| 38 |
.ie t .ds `` `` |
| 39 |
.el .ds `` "" |
| 40 |
.ie t .ds '' '' |
| 41 |
.el .ds '' "" |
| 42 |
.ie t .ds ' \(aq |
| 43 |
.el .ds ' ' |
| 44 |
.\} |
| 45 |
. |
| 46 |
.de bP |
| 47 |
.ie n .IP \(bu 4 |
| 48 |
.el .IP \(bu 2 |
| 49 |
.. |
| 50 |
. |
| 51 |
.SH NAME |
| 52 |
\fB\%clear\fP \- |
| 53 |
clear the terminal screen |
| 54 |
.SH SYNOPSIS |
| 55 |
.B clear |
| 56 |
.RB [ \-x ] |
| 57 |
.RB [ \-T\ \c |
| 58 |
.IR terminal-type ] |
| 59 |
.PP |
| 60 |
.B "clear \-V" |
| 61 |
.SH DESCRIPTION |
| 62 |
\fB\%clear\fP clears your terminal's screen and its scrollback buffer, |
| 63 |
if any. |
| 64 |
\fB\%clear\fP retrieves the terminal type from the environment |
| 65 |
variable \fITERM\fP, |
| 66 |
then consults the \fIterminfo\fP terminal capability database entry for |
| 67 |
that type to determine how to perform these actions. |
| 68 |
.PP |
| 69 |
The capabilities to clear the screen and scrollback buffer are named |
| 70 |
\*(``clear\*('' and \*(``E3\*('', respectively. |
| 71 |
The latter is a \fIuser-defined capability\fP, |
| 72 |
applying an extension mechanism introduced in \fI\%ncurses\fP 5.0 |
| 73 |
(1999). |
| 74 |
.SH OPTIONS |
| 75 |
\fB\%clear\fP recognizes the following options. |
| 76 |
.TP 9 \" "-T type" + 2n |
| 77 |
.B \-T \fItype\fP |
| 78 |
produces instructions suitable for the terminal \fItype\fP. |
| 79 |
Normally, |
| 80 |
this option is unnecessary, |
| 81 |
because the terminal type is inferred from the environment variable |
| 82 |
\fITERM\fP. |
| 83 |
If this option is specified, |
| 84 |
\fB\%clear\fP ignores the environment variables \fILINES\fP and |
| 85 |
\fI\%COLUMNS\fP as well. |
| 86 |
.TP |
| 87 |
.B \-V |
| 88 |
reports the version of \fI\%ncurses\fP associated with this program and |
| 89 |
exits with a successful status. |
| 90 |
.TP |
| 91 |
.B \-x |
| 92 |
prevents \fB\%clear\fP from attempting to clear the scrollback buffer. |
| 93 |
.SH PORTABILITY |
| 94 |
Neither IEEE Std 1003.1/The Open Group Base Specifications Issue\ 7 |
| 95 |
(POSIX.1-2008) nor X/Open Curses Issue\ 7 documents \fB\%clear\fP. |
| 96 |
.PP |
| 97 |
The latter documents \fBtput\fP, |
| 98 |
which could be used to replace this utility either via a shell script or |
| 99 |
by an alias |
| 100 |
(such as a symbolic link) |
| 101 |
to run \fB\%tput\fP as \fB\%clear\fP. |
| 102 |
.SH HISTORY |
| 103 |
A \fBclear\fP command using the \fItermcap\fP database and library |
| 104 |
appeared in 2BSD (1979). |
| 105 |
.\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/clear.c |
| 106 |
Eighth Edition Unix (1985) later included it. |
| 107 |
.PP |
| 108 |
The commercial Unix arm of AT&T adapted a different BSD program |
| 109 |
(\fBtset\fP) to make a new command, |
| 110 |
\fBtput\fP, |
| 111 |
and replaced the \fBclear\fP program with a shell script that called |
| 112 |
\*(``\fBtput clear\fP\*(''. |
| 113 |
.PP |
| 114 |
.RS 4 |
| 115 |
.EX |
| 116 |
.nf |
| 117 |
/usr/bin/tput ${1:+\-T$1} clear 2> /dev/null |
| 118 |
exit |
| 119 |
.fi |
| 120 |
.EE |
| 121 |
.RE |
| 122 |
.PP |
| 123 |
In 1989, when Keith Bostic revised the BSD \fBtput\fP command |
| 124 |
to make it similar to AT&T's \fBtput\fP, |
| 125 |
he added a \fBclear\fP shell script as well. |
| 126 |
.\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=Net2/usr/src/usr.bin/\ |
| 127 |
.\" tput/clear.sh |
| 128 |
.PP |
| 129 |
.RS 4 |
| 130 |
.EX |
| 131 |
exec tput clear |
| 132 |
.EE |
| 133 |
.RE |
| 134 |
.PP |
| 135 |
The remainder of the script in each case is a copyright notice. |
| 136 |
.PP |
| 137 |
In 1995, |
| 138 |
\fI\%ncurses\fP's \fBclear\fP began by adapting BSD's original |
| 139 |
\fBclear\fP command to use \fIterminfo\fP. |
| 140 |
The \fBE3\fP extension came later. |
| 141 |
.bP |
| 142 |
In June 1999, \fIxterm\fP provided an extension to the standard control |
| 143 |
sequence for clearing the screen. |
| 144 |
Rather than clearing just the visible part of the screen using |
| 145 |
.RS 8 |
| 146 |
.PP |
| 147 |
.EX |
| 148 |
printf \*'\e033[2J\*' |
| 149 |
.EE |
| 150 |
.RE |
| 151 |
.IP |
| 152 |
one could clear the scrollback buffer as well by using |
| 153 |
.RS 8 |
| 154 |
.PP |
| 155 |
.EX |
| 156 |
printf \*'\e033[\fB3\fPJ\*' |
| 157 |
.EE |
| 158 |
.RE |
| 159 |
.IP |
| 160 |
instead. |
| 161 |
\*(``XTerm Control Sequences\fP\*('' documents this feature as |
| 162 |
originating with \fIxterm\fP. |
| 163 |
.bP |
| 164 |
A few other terminal emulators adopted it, |
| 165 |
such as PuTTY in 2006. |
| 166 |
.bP |
| 167 |
In April 2011, a Red Hat developer submitted a patch to the Linux |
| 168 |
kernel, modifying its console driver to do the same thing. |
| 169 |
Documentation of this change, |
| 170 |
appearing in Linux 3.0, |
| 171 |
did not mention \fIxterm\fP, |
| 172 |
although that program was cited in the Red Hat bug report (#683733) |
| 173 |
motivating the feature. |
| 174 |
.bP |
| 175 |
Subsequently, |
| 176 |
more terminal developers adopted the feature. |
| 177 |
The next relevant step was to change the \fI\%ncurses\fP \fBclear\fP |
| 178 |
program in 2013 to incorporate this extension. |
| 179 |
.bP |
| 180 |
In 2013, |
| 181 |
the \fBE3\fP capability was not exercised by |
| 182 |
\*(``\fB\%tput clear\fP\*(''. |
| 183 |
That oversight was addressed in 2016 by reorganizing \fB\%tput\fP to |
| 184 |
share its logic with \fB\%clear\fP and \fB\%tset\fP. |
| 185 |
.SH SEE ALSO |
| 186 |
\fB\%tput\fP(1), |
| 187 |
\fB\%xterm\fP(1), |
| 188 |
\fB\%terminfo\fP(5) |