Can colorized output be captured via shell redirect?

billc picture billc · Aug 18, 2010 · Viewed 30.5k times · Source

Various bash commands I use -- fancy diffs, build scripts, etc, produce lots of color output.

When I redirect this output to a file, and then cat or less the file later, the colorization is gone -- presumably b/c the act of redirecting the output stripped out the color codes that tell the terminal to change colors.

Is there a way to capture colorized output, including the colorization?

Answer

ataylor picture ataylor · Aug 18, 2010

One way to capture colorized output is with the script command. Running script will start a bash session where all of the raw output is captured to a file (named typescript by default).