I am using FreeBSD with the csh shell. As an example, in the terminal / screen I get color output for ls (eg. ls -lGs). But when I pipe it through more (eg ls -lGs | more) the output has no colour. Is there a way to have more also display color?
1 Answer
I solved the problem in two steps.
First I set the environment varable CLICOLOR_FORCE in .cshrc to force output other then to TERM to also use colors, eg:
CLICOLOR_FORCE 1
more has a command line option -R to output color sequences.
-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 cor- rectly in most cases. ANSI "color" escape sequences are sequences of the form:
These two combined gave me the desired results, so
ls -lGs | more -R
now displays the output in color.
-
Glad you found a solution: for the record, your answer doesn't work with my configuration of Ubuntu/
bash
with GNUls
, but this is a long way from FreeBSD/csh
, so it's not surprising. In my casemore
has no-R
option, but it works without.– AFHMay 24, 2016 at 19:54 -
Should I add the FreeBSD tag to the question? It might work on other systems... They question and answer should be clear enough.– Lexib0yMay 24, 2016 at 21:31
-
I'm not sure what to advise: I have seen reference to
CLICOLOR_FORCE
on other systems, and my comments should help when your solution doesn't work. I have no idea how many people will come upon this solution by searching on the tag, rather than the title, but I suspect not many.– AFHMay 24, 2016 at 22:15
ls
has the--color
option, andls --color=always
retains colouring when output is redirected.