clear_console only works on a real Linux virtual console, so running it over SSH gets you a failure, not a cleared screen. This guide gets you clearing the right terminal and reading that failure correctly when it is the wrong one. The installed command comes from the Ubuntu bash package, version 5.2.21-2ubuntu4 on the machine used for this guide.
Safety checkpoint: clearing a console is reversible only in the sense that the running programs and files remain unchanged. The visible terminal history is removed from view, so save any text you still need before running the command. Do not use it as a substitute for recording logs or command output.
Start with ordinary, read-only checks. They do not need elevated privileges and do not clear anything:
$ command -v clear_console
/usr/bin/clear_console
$ dpkg-query -W -f='${Package} ${Version}\n' bash
bash 5.2.21-2ubuntu4
The manual describes clear_console as a command with no arguments. The installed executable also provides its own help and version options, so check the executable when writing a script or troubleshooting a particular host:
$ clear_console --help
Usage: clear_console [option]
valid options are:
-q --quiet don't print error messages
-h --help display this help text and exit
-V --version display version information and exit
$ clear_console --version
clear_console: Version 0.1
The help output is the installed program's contract here. It is more specific than the short local manpage, which documents the no-argument invocation but does not list these options.
clear_console is for a Linux virtual console, such as /dev/tty1. It is not a general-purpose clear-screen command for every terminal emulator, SSH session or pseudo-terminal. Check the terminal device without changing it:
$ tty
/dev/tty1
Your device number will differ. A path beginning /dev/tty can indicate a virtual console, but do not treat that as proof on an unusual setup. An SSH session normally reports a pseudo-terminal such as /dev/pts/2; a graphical terminal emulator also normally uses a pseudo-terminal. For those environments, use the terminal emulator's own reset or clear function, or the separate clear command.
Checkpoint: if tty reports a pseudo-terminal, stop here unless your goal is specifically to observe the documented failure. Adding sudo will not turn a pseudo-terminal into a virtual console.
On the target virtual console, run the command with no arguments:
$ clear_console
On success, the screen is cleared and the command normally writes no diagnostic text. The command looks up the terminal type from the environment, consults the terminfo database, and switches the foreground virtual terminal away and back while clearing the buffer. It therefore needs a usable terminal environment and access to the virtual-console controls.
Check the exit status immediately if you are using it in a script:
$ clear_console
$ status=$?
$ printf 'clear_console status: %s\n' "$status"
clear_console status: 0
The visible result is the main verification. The status check confirms the program did not report a failure. It does not provide a way to recover text already cleared from the screen.
clear is the usual choice for a terminal emulator or an SSH session. It emits terminal control sequences based on the terminal type. clear_console has a narrower purpose: it attempts to clear a Linux virtual console, including its console buffer, by changing the foreground virtual terminal temporarily.
clear when the current terminal is a normal terminal emulator, SSH pseudo-terminal or other terminal described by its terminal type.clear_console when the command is deliberately tied to a Linux virtual console and clearing its buffer is part of the requirement.Neither command is a logging mechanism. If the output matters, capture it before clearing:
$ some-command 2>&1 | tee /path/to/recorded-output.txt
$ clear_console
Replace /path/to/recorded-output.txt with a destination you have checked. The tee pipeline changes state by creating or overwriting that file, so choose a new path or make a backup first.
Run this test only when you want to confirm how the installed command behaves away from a virtual console:
$ clear_console
clear_console: terminal is not a console
$ printf 'clear_console status: %s\n' "$?"
clear_console status: 1
The exact diagnostic is from the installed version and the status is non-zero. This usually means the command is being run from a pseudo-terminal or another terminal that is not a Linux virtual console. Check tty, reconnect to the intended local console if appropriate, and try again there.
For a script that probes several environments, --quiet suppresses the error message but keeps the failure status:
$ clear_console --quiet
$ printf 'clear_console status: %s\n' "$?"
clear_console status: 1
Use quiet mode only when the caller handles the status. Suppressing the message can make a failed clear look like a successful no-op in an interactive support session.
Do not start by changing TERM at random. The command uses the terminal type to find clearing capabilities, and a false value can create a different failure or an incorrect sequence. Check the value first:
$ printf 'TERM=%s\n' "$TERM"
TERM=linux
$ infocmp "$TERM" >/dev/null && echo 'terminfo entry found'
terminfo entry found
If infocmp reports that the entry is missing, fix the terminal environment or installed terminfo data through your normal system administration process. Do not guess a replacement terminal type.
Do not run the command through ssh and expect it to clear the remote machine's physical console. It will see the SSH client's pseudo-terminal. Likewise, running it from a shell inside a graphical terminal does not make that shell a virtual console.
Elevated privileges are normally unnecessary. If the command fails because the current terminal is not a console, sudo clear_console addresses the wrong problem. Use root only if a separately verified device-permission problem is the cause, and test the ordinary invocation first.
clear_console returned status 0 and the console was visibly cleared.clear or their terminal emulator's controls instead.sudo first.