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?
If your shell is bash, add
~/.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
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).
If you don't have
zsh (e.g. you just have
ksh), or you want a way that works in all modern shells, this is how I do it:
test -f "$HOME"/.exitrc && trap ". $HOME/.exitrc" EXIT
type clear >/dev/null 2>&1 && clear
In my case,
.zlogin don't have any commands in them, that way I can just change
.exitrc, rather than having to edit separate files for each shell.
test -f ~/.bashrc && . ~/.bashrc test -f ~/.profile && . ~/.profile
test -f ~/.profile && . ~/.profile
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.