Preserve colors while piping to tee
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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).
pipe tee
add a comment |
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).
pipe tee
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14
add a comment |
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).
pipe tee
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).
pipe tee
pipe tee
edited Nov 1 '11 at 10:39
Paweł Gościcki
asked Nov 1 '11 at 10:28
Paweł GościckiPaweł Gościcki
94421222
94421222
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14
add a comment |
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14
add a comment |
2 Answers
2
active
oldest
votes
Simply insert unbuffer
before any command to make it think it is writing to an interactive output even if it is actually piping into another executable. This will preserve color in the case of ls
.
For example
unbuffer ls -l --color=auto | tee output.log
If you don't already have it installed, on Ubuntu and other Debian-ish Linux distributions you can install unbuffer
by doing.
sudo apt-get install expect-dev
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output ofxcodebuild
— instead I got chopped-up lines with no color.unbuffer xcodebuild | less -R
worked flawlessly, however.
– Slipp D. Thompson
Nov 24 '15 at 5:33
1
You don't need theexpect-dev
package.expect
is enough.
– Yajo
Sep 4 '18 at 9:53
|
show 2 more comments
Use the ls option --color=always
--color=auto
will not color output to a pipeline - for obvious reasons.
The main page says the following:
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).
1
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 totee
. And I want to "fix/change" tee/pipe, not the command I'm executing.
– Paweł Gościcki
Nov 2 '11 at 12:00
1
@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
3
@PawełGościcki this answer only fixes the problem forls
. See my answer that fixes the problem for all programs, including heroku logs.
– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
|
show 2 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f352697%2fpreserve-colors-while-piping-to-tee%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply insert unbuffer
before any command to make it think it is writing to an interactive output even if it is actually piping into another executable. This will preserve color in the case of ls
.
For example
unbuffer ls -l --color=auto | tee output.log
If you don't already have it installed, on Ubuntu and other Debian-ish Linux distributions you can install unbuffer
by doing.
sudo apt-get install expect-dev
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output ofxcodebuild
— instead I got chopped-up lines with no color.unbuffer xcodebuild | less -R
worked flawlessly, however.
– Slipp D. Thompson
Nov 24 '15 at 5:33
1
You don't need theexpect-dev
package.expect
is enough.
– Yajo
Sep 4 '18 at 9:53
|
show 2 more comments
Simply insert unbuffer
before any command to make it think it is writing to an interactive output even if it is actually piping into another executable. This will preserve color in the case of ls
.
For example
unbuffer ls -l --color=auto | tee output.log
If you don't already have it installed, on Ubuntu and other Debian-ish Linux distributions you can install unbuffer
by doing.
sudo apt-get install expect-dev
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output ofxcodebuild
— instead I got chopped-up lines with no color.unbuffer xcodebuild | less -R
worked flawlessly, however.
– Slipp D. Thompson
Nov 24 '15 at 5:33
1
You don't need theexpect-dev
package.expect
is enough.
– Yajo
Sep 4 '18 at 9:53
|
show 2 more comments
Simply insert unbuffer
before any command to make it think it is writing to an interactive output even if it is actually piping into another executable. This will preserve color in the case of ls
.
For example
unbuffer ls -l --color=auto | tee output.log
If you don't already have it installed, on Ubuntu and other Debian-ish Linux distributions you can install unbuffer
by doing.
sudo apt-get install expect-dev
Simply insert unbuffer
before any command to make it think it is writing to an interactive output even if it is actually piping into another executable. This will preserve color in the case of ls
.
For example
unbuffer ls -l --color=auto | tee output.log
If you don't already have it installed, on Ubuntu and other Debian-ish Linux distributions you can install unbuffer
by doing.
sudo apt-get install expect-dev
answered May 9 '14 at 22:37
Eamonn O'Brien-StrainEamonn O'Brien-Strain
85674
85674
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output ofxcodebuild
— instead I got chopped-up lines with no color.unbuffer xcodebuild | less -R
worked flawlessly, however.
– Slipp D. Thompson
Nov 24 '15 at 5:33
1
You don't need theexpect-dev
package.expect
is enough.
– Yajo
Sep 4 '18 at 9:53
|
show 2 more comments
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output ofxcodebuild
— instead I got chopped-up lines with no color.unbuffer xcodebuild | less -R
worked flawlessly, however.
– Slipp D. Thompson
Nov 24 '15 at 5:33
1
You don't need theexpect-dev
package.expect
is enough.
– Yajo
Sep 4 '18 at 9:53
5
5
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
Another solution, which does not require installing anything, is at stackoverflow.com/questions/3515208/…
– Tgr
Jan 31 '15 at 2:51
2
2
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
This causes the resulting file to contain color codes (of course); is there any way to then print the file in a way that makes use of the color codes and properly displays the colors in the terminal?
– Kyle Strand
Jul 10 '15 at 18:48
1
1
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
Ugh, that makes password entries show your password in cleartext!
– AndiDog
Aug 20 '15 at 13:37
@Tgr That solution didn't work for me on OS X trying to get the raw colored output of
xcodebuild
— instead I got chopped-up lines with no color. unbuffer xcodebuild | less -R
worked flawlessly, however.– Slipp D. Thompson
Nov 24 '15 at 5:33
@Tgr That solution didn't work for me on OS X trying to get the raw colored output of
xcodebuild
— instead I got chopped-up lines with no color. unbuffer xcodebuild | less -R
worked flawlessly, however.– Slipp D. Thompson
Nov 24 '15 at 5:33
1
1
You don't need the
expect-dev
package. expect
is enough.– Yajo
Sep 4 '18 at 9:53
You don't need the
expect-dev
package. expect
is enough.– Yajo
Sep 4 '18 at 9:53
|
show 2 more comments
Use the ls option --color=always
--color=auto
will not color output to a pipeline - for obvious reasons.
The main page says the following:
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).
1
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 totee
. And I want to "fix/change" tee/pipe, not the command I'm executing.
– Paweł Gościcki
Nov 2 '11 at 12:00
1
@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
3
@PawełGościcki this answer only fixes the problem forls
. See my answer that fixes the problem for all programs, including heroku logs.
– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
|
show 2 more comments
Use the ls option --color=always
--color=auto
will not color output to a pipeline - for obvious reasons.
The main page says the following:
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).
1
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 totee
. And I want to "fix/change" tee/pipe, not the command I'm executing.
– Paweł Gościcki
Nov 2 '11 at 12:00
1
@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
3
@PawełGościcki this answer only fixes the problem forls
. See my answer that fixes the problem for all programs, including heroku logs.
– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
|
show 2 more comments
Use the ls option --color=always
--color=auto
will not color output to a pipeline - for obvious reasons.
The main page says the following:
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).
Use the ls option --color=always
--color=auto
will not color output to a pipeline - for obvious reasons.
The main page says the following:
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).
edited Feb 4 at 13:42
Run5k
11.7k73354
11.7k73354
answered Nov 1 '11 at 12:01
RedGrittyBrickRedGrittyBrick
67.5k13106163
67.5k13106163
1
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 totee
. And I want to "fix/change" tee/pipe, not the command I'm executing.
– Paweł Gościcki
Nov 2 '11 at 12:00
1
@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
3
@PawełGościcki this answer only fixes the problem forls
. See my answer that fixes the problem for all programs, including heroku logs.
– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
|
show 2 more comments
1
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 totee
. And I want to "fix/change" tee/pipe, not the command I'm executing.
– Paweł Gościcki
Nov 2 '11 at 12:00
1
@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
3
@PawełGościcki this answer only fixes the problem forls
. See my answer that fixes the problem for all programs, including heroku logs.
– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
1
1
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
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
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
1
1
@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
@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
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
3
3
@PawełGościcki this answer only fixes the problem for
ls
. See my answer that fixes the problem for all programs, including heroku logs.– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
@PawełGościcki this answer only fixes the problem for
ls
. See my answer that fixes the problem for all programs, including heroku logs.– Eamonn O'Brien-Strain
Jun 16 '14 at 3:25
|
show 2 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f352697%2fpreserve-colors-while-piping-to-tee%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Already asked on Unix&Linux.
– Dan Dascalescu
Sep 15 '16 at 22:14