Shell console clearing

Is there a way to clear up what is displayed on the shell console (in ubuntu linux) in just a single key or two? When I get flood of lines from grep and that exceeds the height of the window, I want to quickly scroll back to the position where I typed the command after the prompt. I can do so if I had opened a fresh terminal before I type the command, and just go to the initial position. But if keep using the same terminal window, I have to manually find the position. Ctrl+l is not an answer because it just scrolls, and the contents of the terminal remains. I cannot use less because the colored output of grep does not show up in color.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The

reset

command, which is part of ncurses, and is
located in the ncurses-bin package on Debian, will completely clear the console. Is that what you want?

Brief summary of reset from the man page:

reset sets cooked and echo modes,
turns off cbreak and raw modes, turns
on new-line translation and resets any
unset special characters to their
default values before doing terminal
initialization the same way as tset.

As discussed in https://superuser.com/questions/122911/bash-reset-and-clear-commands, and as pointed out by Erik in Shell console clearing, clear will just clear the screen, reset will (as bignose put it), “reset your terminal when it gets messed up by control sequences”. Personally, I’m good at messing up my terminal, and when I clear it, I’m not looking to get anything back that was there before, so I just use reset. But ymmv.

Method 2

I usually just use:

clear

From the clear man page:

clear clears your screen if this is possible.  It looks in the environ-
ment for the terminal type and then in the terminfo database to  figure
out how to clear the screen.

clear ignores any command-line parameters that may be present.

Method 3

It’s not an answer to your question, but you can use less, and maintain your color see: https://serverfault.com/questions/26509/colors-in-bash-after-piping-through-less

hint:

$ grep --color=always foo bar.txt | less -r

Method 4

You can try this command:

tput reset


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x