What commands can I use to reset and clear my terminal?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Island
--
Chapters
00:00 What Commands Can I Use To Reset And Clear My Terminal?
00:34 Accepted Answer Score 79
01:06 Answer 2 Score 69
01:58 Answer 3 Score 33
02:54 Answer 4 Score 11
03:21 Thank you
--
Full question
https://superuser.com/questions/122911/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#unix #terminal
#avk47
ACCEPTED ANSWER
Score 79
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'
ANSWER 2
Score 69
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
head
to stream just the first few (choose how many, with-n
) lines of text output.Use a pager program such as
less
ormost
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.
- With GNU
ANSWER 3
Score 33
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"'
ANSWER 4
Score 11
Probably the best way of clearing everything is to use the terminal's function:
- Konsole: Ctrl+Shift+K View → Clear Scrollback and Reset
- GNOME Terminal: Edit → Reset and Clear
- PuTTY: Ctrl+right-click → Clear Scrollback
This way both buffers are wiped clean, and the terminal state is reset to exactly what it was on startup (which may or may not be the same as using reset
).