User Tools

Site Tools


How To Clear Your Terminal Screen

There you are, happily – but surreptitiously – playing away at a vintage game of “Adventure,” when… suddenly, you see the boss approaching! Quick! Don't get caught! How to erase the evidence of your dalliance?

Well. Since you're playing vintage, text-mode “Adventure,” you're playing it in (or on) a terminal screen – either an antique VT100/200 (etc.), or more likely, in a terminal emulation window (on your PC) like PuTTY, Reflection, TeraTerm, or similar. These are all ANSI-standards-based terminals (even the emulated terminal windows), and they'll all respond to the ANSI escape-sequence (command) to “erase the screen” – thus saving you from embarrassment and a scolding from your boss.

How? It just takes a bit of set-up work in your personal VMS LOGIN.COM command file. You need to create a command alias – like CLS – which you can quickly enter (type) as a command at the DCL $-prompt to “clear the screen now!” “CLS” is a handy mnemonic and abbreviation for “clear screen” – make up your own if you don't like this one. Keep it short and sweet, so you can remember and enter it in a hurry!

Edit your own LOGIN.COM file to add this (first approximation) alias command under the INTERACTIVE section (or label) of that file:


Exit from your text editor, saving your changes – To try this out, execute your command file interactively to define the new alias command:


…and then try your new command:

$ cls

If you've made no typos in the above, any residual text on your screen should vanish, replaced with a clean white (or black?) screen with your $-prompt in the upper-left-hand corner, and the cursor blinking happily to its right. It can't get much better than this!… Or can it?

It turns out that this preliminary version of our CLS alias command elicits the right behavior, but it's pretty “expensive” to execute, especially when what's required to clear an ANSI-terminal screen is a command of about 10 ASCII characters. This preliminary version:

  1. Processes and parses a native DCL command to…
  2. Run a whole executable program, the SYS$SYSTEM:TYPE.EXE program image, which…
  3. Must then be page-faulted into your interactive process's working set to…
  4. Execute code which ultimately spits out a 10-character “clear the screen” ANSI escape sequence.
  5. Whew!

That's actually a lot of work for VMS and DCL to do just to clear your terminal screen. This can be done much more efficiently, at the expense of just a little bit more setup in your LOGIN.COM file:

$ esc[0,8]= %X1B                !  27 decimal,  033 octal - ESCape character
$ _bckscrL  = esc + "[?5h"      ! set background light
$ _bckscrD  = esc + "[?5l"      ! set background dark
$ _clrscr   = esc + "[m"  -     ! set rendition normal
            + esc + "[H"  -     ! cursor to 0,0
            + esc + "[2J"       ! clear entire screen
$ !
$ cls      == "WRITE sys$output _clrscr"
$ clsd     == "WRITE sys$output _bckscrL,_clrscr"
$ clsl     == "WRITE sys$output _bckscrD,_clrscr"

Cut-&-paste the above lines into your LOGIN.COM file, this time replacing the previous “cls == TYPE /PAGE…” command with these lines. Exit from your text editor session again, saving your work, then:


…and then try your new command:

$ cls

Again, your screen should clear just fine. So!… Why is the above better than the first/preliminary version?

  • This new version does not run an entire program image.
  • Instead, it simply uses DCL's built-in WRITE command (which does not run a whole program, DCL can do a WRITE operation by itself) to simply spit-out the clear-screen ANSI escape-sequence (command) to SYS$OUTPUT (your terminal screen itself).

Those somewhat complicated commands in this second example do this:

  1. The first line creates a local DCL variable (symbol) named esc which contains a single ASCII “escape character” (ASCII code value 27, or 33-octal, or 1B-hex).
  2. In the next three commands (spanning five lines), that esc (escape) character is used to construct three more DCL variables (each beginning with an underscore “_” character to stress their intermediate nature) which are escape-sequence commands to (in order): _bckscL: set the terminal's background to light (white); _bckscD: set the terminal's background to dark (black); and _clrscr: clear the entire screen.
  3. The final three commands (lines after the blank comment line) simply construct global DCL command aliases for: clr: Clear the screen; clsd: Clear the screen, make background dark (black); and clsl: Clear the screen, make background light (white).

In other words, clsl and clsd will change your screen's background to light or dark (respectively) while clearing it, and cls will simply clear the screen retaining the current background. Try 'em out!

For more information (TL;DR) about ANSI escape-sequences, see Wikipedia:

howto/clear_your_terminal_screen.txt · Last modified: 2018/09/10 21:38 by lricker

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki