6

I'd like to view logfiles with colored output, scrollable and searchable. How do I do that?

I tried less /var/log/syslog | ccze | grep error, but it is not scrollable.

6

That's because you're doing it the wrong way around. It's less that is scrollable so that needs to be the last command in the pipeline:

grep error /var/log/syslog | ccze -A | less -R

The options used are:

-A, --raw-ansi

If one wants to enable raw ANSI color sequences instead of using curses, this option does just that.

This makes ccze use ANSI color codes instead of curses. While less can deal with ANSI escapes with the -R option (see below), curses are more of a problem. Using the -A option of ccze neatly sidesteps that issue.

-R or --RAW-CONTROL-CHARS Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases. ANSI "color" escape sequences are sequences of the form:

ESC [ ... m

where the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSI color escape sequences are assumed to not move the cursor. You can make less think that characters other than "m" can end ANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence. And you can make less think that characters other than the standard ones may appear between the ESC and the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.

2
  • Unfortunately, that didn't work. Even worse, it freezes my terminal while giving random character output.
    – user430
    Mar 20 '16 at 17:04
  • @user430 ah, yes, sorry. The less command needs the -R flag in order to interpret the color codes correctly. Also, ccze apparently uses ncruses output by default so you also need -A to disable that. Try the updated answer.
    – terdon
    Mar 20 '16 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.