What commands can I use to reset and clear my terminal?

The scrollback buffer is not a feature of bash but of the terminal program. You didn't say what terminal you using.

If you are using xterm you might be able to clear the saved lines by echoing ESC-c to the terminal.

This may or may not work on whatever terminal program you are using.

On linux this will probably work:

echo -e '\0033\0143'

on FreeBSD echo doesn't accept -e so you can try:

printf '\033\143'

Use the right tool for each job:

  • Use clear to clear the terminal window.

  • Use reset to reset your terminal when it gets messed up by control sequences.

  • Use cat only when you want to stream a whole lot of data from one place to another uninterrupted.

  • Use a pager program such as less or most to view pages of output.

  • Use tail -f /var/log/foo.log /var/log/bar.log to watch several different log files.

    • With GNU tail, the -F option is better because it can continue following the file even when a new file appears in its place, as is common for log files.

Just to provide the technical answer: reset reinitialize the terminal, as if it was reopened from scratch. stty sane will do a lot of the same functionality (without the reset). This is the same thing as ^L (Ctrl+L) (irrc), and tput clear. Despite what the previous poster (@grawity) said, clear does not output a bunch of newlines. It sends the TERM's reset as defined in terminfo or termcap, for me, using gnome-terminal (xterm) it is the same as the command perl -e'print "\33[H\33[2J"'.

If you want to just clear the buffer -- as compared to reseting the whole terminal, try this tput reset. It should be very fast, and do what you want. (Though you really should be reading files with less)

tput reset, sends the terminfo value for reset -- on my terminal (xterm) it is the same as perl -e'print "\33c"'

Tags:

Unix

Terminal