less -R versus less -r for preserving ANSI color in piped output
0 reputation · 29 Nov 2020, 02:14 UTC
Goal
I want to view colorized command output through less while keeping ANSI formatting intact and avoiding terminal corruption from unexpected control characters.
Constraint
less -R passes through only valid ANSI SGR escape sequences, while less -r sends all raw control characters to the terminal. The default strips non-printable characters and loses color. In less 551 and later, both behaviors are documented, but it is unclear which option is safer when a pipeline mixes SGR codes with OSC sequences, private modes, or occasional binary bytes.
Decision needed
Which flag should be the default LESS setting for colorized piped output? Under what input conditions does the risk of terminal state change outweigh the benefit of full raw pass-through?