6

Currently on my laptop when I log out I can still see traces of my last activities (in tty). How can I tell it (Gentoo) to clear the screen before logging out?

Caleb
  • 70,105
phunehehe
  • 20,240

3 Answers3

9

If your shell is bash, add clear_console or reset to ~/.bash_logout. If your shell is zsh, add that command to ~/.zlogout. You might want to run this only when the shell is a login shell on a Linux console, e.g.

if [[ "`tty`" = /dev/tty[1-9] && $(ps -o comm= -p $PPID) = login ]]; then
  clear_console
fi

As the system administrator, you can configure the console to always be cleared before showing the login prompt. The easiest way to do that is to use mingetty instead of getty; you lose support for serial consoles but gain a few features such as screen clearing. First install mingetty. Then, assuming you use SysVinit, in /etc/inittab, change lines like 1:2345:respawn:/sbin/getty 38400 tty1 into

1:2345:respawn:/sbin/mingetty tty1

The Upstart equivalent would to change exec /sbin/getty -8 38400 tty1 to exec /sbin/mingetty tty1 in /etc/init/tty1.conf (these are Ubuntu paths, you may need some adjustments for Gentoo).

  • 3
    One other way I use (if you have root) is to add \e[2J\e[f to the beginning of /etc/issue, so the screen gets cleared as part of drawing the login prompt. I like clear_console in .bash_logout more though – Michael Mrozek Nov 12 '10 at 18:18
0

If you don't have bash or zsh (e.g. you just have ksh), or you want a way that works in all modern shells, this is how I do it:

.profile

test -f "$HOME"/.exitrc && trap ". $HOME/.exitrc" EXIT

.exitrc

type clear >/dev/null 2>&1 && clear

In my case, .bash_profile and .zlogin don't have any commands in them, that way I can just change .profile or .exitrc, rather than having to edit separate files for each shell.

.bash_profile

test -f ~/.bashrc && . ~/.bashrc
test -f ~/.profile && . ~/.profile

.zlogin

test -f ~/.profile && . ~/.profile
Mikel
  • 57,299
  • 15
  • 134
  • 153
0

If you don't want to edit anything and you don't need to clear the screen every time, pressing ctrl+c works for clearing the screen back to a login prompt.

Vreality
  • 178