5

I noticed this in my default bash_logout:

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

I was curious why it didn't just use clear. Googling didn't enlighten me, but it did show me tput clear and tput reset.

What are the differences between the various options for clearing the screen?

Andrew
  • 1,115

1 Answers1

5

On my debian system, /usr/bin/clear and /usr/bin/tput are part of the ncurses-bin package, and /usr/bin/clear_console is part of the bash package.

Why should the default .bash_logout assume that the ncurses-bin package is installed?

Also, if run from a Linux virtual terminal (not from a serial or pseudo tty) clear_console(1) will also clear the scrollback buffer (in addition to sending the clear/cl terminfo escape).

It will do that by switching back and forth to another vt [1], and by sending the \e[3J "flush scrollback" escape.

On newer systems, clear and tput clear will also send that \e[3J escape (but not on many distros still in use, eg. Centos 7 or Debian 9 -- on the latter, the TERM environment variable should be set to linux3.0, which is not the default).

See the source of clear_console here.

[1] which may be defeated by the vgacon.scrollback_persistent=1 boot param, if your kernel was compiled with the VGACON_SOFT_SCROLLBACK option ("Enable Scrollback Buffer in System RAM").

  • 1
    That's interesting, but since ncurses-bin is a required package, your comment about it is unfounded and should be deleted. There's no evidence that the packager took any of that into account. – Thomas Dickey Jul 15 '19 at 09:59
  • 1
    ncurses-bin is NOT required by bash. My answer is written from the perspective of a user (sufferer), the politics which led to this situation are neither relevant nor interesting. –  Jul 15 '19 at 10:03