Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in dire need of a way to color my less output while reading a file that is constantly being appended.

The file in questions is a Resin servlet container log.

My current "implementation" of the color scheme works using tail -F and sed for editing in colors around keywords. I have four words to color: INFO, WARN, ERROR, DEBUG, one of which occurs once per line.

I have tried using the LESSOPENenvironment variable, but I can't seem to keep reading the log. The file is not tailed once it has been open.

I have very little control over the server, and cannot really install anything other than my own scripts in my home folder, so no packages. The server in question is a RHEL 6.4.

The problem is that less does not keep reading the file. Is there a way to tail the log continuously using the LESSOPENenvironment variable, or do I need some more complex tools?

share|improve this question
Is the file already coloured using ANSI escape sequences or do you need to add the colours as well? – Marco Mar 27 '13 at 12:49
You haven't stated your exact problem. What is not working? Is less not getting new output, is it stripping the colors, what? – Patrick Mar 27 '13 at 13:06
Colors are working, less is not tailing, it just reads what the file looks like when it's first opened. – Jes Mar 27 '13 at 13:09
have a look at multitail – Ulrich Dangel Mar 27 '13 at 13:33
Shift-f does not tail it. multitail is not an option, can't install anything on the server. – Jes Mar 27 '13 at 14:01

I see two questions here:

  • How do I color output in less
  • How do I make less behave like tail -f

I can't answer the first one, though LESSOPEN seems like a good avenue. The second one is easy: start less as less +F or hit ShiftF if less is already running.

share|improve this answer

You could run tail -f in an Emacs shell buffer, and let Emacs do the coloring.

Hi Lock lets you quickly highlight words matching a regexp. There's a crude way to save highlighting patterns in a file, but it won't be convenient when the file is actually the output of a command. You're probably better off writing a simple major mode with font lock keywords.

share|improve this answer
up vote 1 down vote accepted

The problem lies in the pipes on linux. CTRLc closes the pipe and less cannot reopen the pipe.

The solution I found viable was to redirect the colored log to a file, then read that file with less. A file can be tailed after a CTRL-c, and I therefore just do the following:

tail -F -c +1 | colorize > /tmp/logfilename &
less -Sr /tmp/logfilename

Works like a charm.

share|improve this answer

I use vim to simulate colored less. It has a less macro and uses the Vim color scheme.

I added this to my bashrc:

alias cless='/usr/share/vim/vim73/macros/less.sh'

For the tailing/following, you will need some Vim plugin that allows for following. Perhaps try the Tail Bundle plugin.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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