1

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?

  • 1
  • I found that question while looking for an answer, but didn't see anything describing what they're doing "under the hood" and how it differs. – Andrew Jul 14 at 23:45
  • The links which I pointed to in my answer to that question go to some detail. The bottom line is that one of the package maintainers decided to do it that way. – Thomas Dickey Jul 15 at 0:45
  • @Andrew I've added some details and links. I hope this makes it a bit more clear (sorry for the pun) than the historical and philosophical notes from the linked answers. – mosvy Jul 15 at 3:21
3

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 at 9:59
  • 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. – mosvy Jul 15 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.