Tuesday, October 24, 2017

command line - How can I clear the console window after grep fills the screen?


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.



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.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...