3 ms·
> Or is there some voodoo by which the ANSI sequences get stripped from the output when redirected to a file? Not quite, but programs in general use some voodo
by irishsultan 5y ago
> Or is there some voodoo by which the ANSI sequences get stripped from the output when redirected to a file?
Not quite, but programs in general use some voodoo to detect when they are being redirected and won't output ANSI codes when they detect that.
Often there will be a flag to enable/disable color, or let it detect when color is desired. On Linux ls accepts the --color=WHEN parameter, where WHEN can be always (`ls --color=always > ls-with-ansi-codes.txt` will output color codes), it can be never (just don't output ANSI codes, no matter whether you detect output redirection) or it can be auto (will show colors when you execute `ls --color=auto` but not when you do `ls --color=auto > ls-without-ansi-codes.txt`).