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.
Add a comment
|
2 Answers
If the console gets jammed/full then:
reset
will clear and reset the state. You can also cause this to be sent via the magic sequence Ctrl-v Esc c Enterclear
if you just want to clear the screen; you might combine it with the output you're after:clear ; grep -r …
(BTW, reboot
is a separate command, so don't worry about accidentally rebooting your machine by using clear
or reset
!).
You can actually stick with using less - try this:
grep --color=always foo * | less -r
That will tell grep to ignore that its output is being piped, and the "-r" on less tells it to pass through raw control characters, which in this case are the color codes.
-
I tried it, but it does not work. Is it interfering with other options? I did
grep -nrI --color=always
– sawaCommented Mar 31, 2011 at 19:12 -
Hm, I did:
grep -nrI --color=always foo * | less -r
and it worked the same, showing colors in less. This was using bash as a shell with TERM set as 'xterm' Commented Mar 31, 2011 at 19:17 -
-
I just tried it in gnome-terminal, the XFCE terminal, and Konsole and it worked in all three. Maybe try with '-R' instead of '-r' on less? That tells it to only accept only ANSI color codes. Maybe some other misc control characters are sneaking through the output of grep. If that does not work, I'm not sure what else would be causing the colors to get eaten. BTW, I am testing this with an up-to-date installation of 10.10 in case versions are the culprit here. Commented Mar 31, 2011 at 19:30
-
I did work. Actually, in my
.bashrc
, I hadgrep
aliased togrep -nrI --color-always
andless
aliased toless -r
, and typing the combination ofgrep
andless
with a pipe on the console did not work, but when I typed the whole line that you gave me directly in the terminal, it worked.– sawaCommented Mar 31, 2011 at 19:36