Gentoo Wiki



Recommended method

Using vi

You can use /etc/issue to clear the terminal by putting ANSI escape sequences in the first line.

vi /etc/issue

Enter insert mode. In the first line type (without the spaces):


you should get this:

File: /etc/issue
This is \n.\O (\s \m \r) \t

This resets the terminal before the issue message is displayed. Note that copy-pasting won't work, you should type that sequence.

If CTRL-ESC brings ProcessTable in KDE try another method using vi:

clear >> /etc/issue
vi /etc/issue

The last line tells vi to move the character sequence generated by clear command to the first line of file, saves the file and exits.

Using emacs

emacs /etc/issue

In the first line type (without the spaces):

C-q ESC [2J C-q ESC [f

Note that C-q means pressing CTRL-q and ESC means pressing the escape key. Also copy-pasting won't work, you should type that sequence.

you should get this:

File: /etc/issue
This is \n.\O (\s \m \r) \t

Using nano

clear >> /etc/issue

Now, open /etc/issue with nano or your favorite editor and move the code to the top of the file.

nano /etc/issue

you should end up with this:

File: /etc/issue
This is \n.\O (\s \m \r) \t 

Using echo

# cp /etc/issue /tmp/issue.old
# echo -e "\x1b\x5b2J\x1b\x5bf" | cat - /tmp/issue.old > /etc/issue

After your satisfied with the results, you may delete your backup file /etc/issue.old.

# rm /tmp/issue.old

Other methods

Method 1

If you are working on a server, or a public workstation, for example in an university, you might want to make sure no-one reads screen-content which is left over by your last session after typing "logout".

To achieve this, you simply need to add the command clear to your ~/.bash_logout.

echo "clear" >> ~/.bash_logout

should do the trick.

Method 2

A variant to method 1 is appending this to /etc/profile (or ~/.bashrc)

File: /etc/profile or ~/.bashrc
alias exit="clear && logout"

Method 3

A variant on Method 2 is to append this to /etc/profile (or ~/.bashrc)

File: /etc/profile or ~/.bashrc
alias exit="reset && logout"

Method 4

If you do clear on logout some of the last lines still will be available "SHIFT+PageUP". This will clear the history.

File: /etc/inittab
# getty-programs for the normal runlevels
# <id>:<runlevels>:<action>:<process>
# The "id" field  MUST be the same as the last
# characters of the device (after "tty").
#1:2345:respawn:/sbin/mingetty --noclear tty1
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

Method 5

Not the best way, but it works.

cp /etc/issue /etc/issue.bak; clear > /etc/issue; cat /etc/issue.bak >> /etc/issue; rm /etc/issue.bak

I use a script to generate my /etc/issue every 15 minutes, so having a 'clear > /etc/issue' at the top was what i did to have this affect.

Method 6

Another dirty way is to flush the screen with a lot of random chars from /dev/urandom before logging out.

cat /dev/urandom & sleep 3; logout

After this, the whole scrollback buffer is overwritten with random chars.

Method 7

Clean and easy: add "trap clear 0" to your /etc/profile - cheerz :)

Method 8

Only tested using bash:

echo -en "\x1b[2J\x1b[f" > /tmp/issue
cat /etc/issue >> /tmp/issue
cat /tmp/issue > /etc/issue
rm /tmp/issue

or short:

(echo -en "\x1b[2J\x1b\f"; cat /etc/issue) > /tmp/issue && mv /tmp/issue /etc/issue

Copy and paste should just work. :) Enjoy.

Clearing the scrollback

The Linux console uses video memory for hardware scrolling. A nice side-effect of this is the availability of scrollback using SHIFT+PageUp etc. Unfortunately, issuing a "clear" command does not clear this scrollback, so simply logging out after issuing the "clear" command will not prevent people seeing what you have been doing.

To prevent leakage of this information, the choices are:

1. Use the "no-scroll" boot parameter to turn off hardware scrolling altogether. Scrolling will be slower if you do this.

2. Use method 6 above to ensure the scrollback buffer is at least full of garbage.


3. Switch to a different virtual console after logging out. The scrollback buffer is not saved to kernel memory, so will not be restored if someone switches back to the console you were using.

4. By changing the console font to lat1-08 and back to its original, the scrollback issue can also be resolved. The following shell script should automate this task:

# Tilman Weiers, 2007
if [ ! -e /tmp/cls.$$ ]; then
 consolechars --old-font=/tmp/cls.$$
 consolechars --font=lat1-08
 consolechars --font=/tmp/cls.$$
 rm /tmp/cls.$$
 echo "failed to create temporary font file"
 exit 1
Retrieved from ""

Last modified: Thu, 02 Oct 2008 08:02:00 +0000 Hits: 24,308