ls -l --color=auto | tee output.log

Without pipe/tee it's colored. How can I make it so that it stays colored while using tee (can be colored only on the screen, I don't care about colors in logs).

link|improve this question

feedback

1 Answer

up vote 1 down vote accepted

Use the ls option --color=always normally it will not color output to a pipeline - for obvious reasons.

The man page says

With --color=auto, color codes are output only if standard output is connected to a terminal (tty).

link|improve this answer
OK. That explains it. But can I still somehow see the colors on the screen? (It's a TTY after all). I don't mind NOT having them in the logfile, but I surely want them on my screen. – Paweł Gościcki Nov 2 '11 at 10:46
I think I made myself not clear enough. ls -l was just an example. I have a completely different command (heroku logs) that strips colors when piped to tee. And I want to "fix/change" tee/pipe, not the command I'm executing. – Paweł Gościcki Nov 2 '11 at 12:00
@Pawel, you can't easily fix it in tee/pipe as tee/pipe are not stripping these color codes. The problem is that the initial command sees it is not writing to the terminal. You need a pseudo-terminal that acts like a pipe but which commands see as a terminal. – RedGrittyBrick Nov 2 '11 at 16:10
Hm... fair enough. I guess I just need to accept that it's how it is. – Paweł Gościcki Nov 3 '11 at 15:08
feedback

Your Answer

 
or
required, but never shown

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