Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 9 down vote accepted

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

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).

share|improve this answer
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

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:


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


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.


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


test -f ~/.profile && . ~/.profile
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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