Less -r or –raw-control-chars option causes “raw” control characters to be displayed. The default is to display control characters using the caret notation; for example, a control-A (octal 001) is displayed as “^A”. Warning: when the -r option is used, less cannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.
Less -R or –RAW-CONTROL-CHARS option is similar to -r option, but only ANSI “color” escape sequences and OSC 8 hyperlink sequences are output in “raw” form. Unlike -r, the screen appearance is maintained correctly, provided that there are no escape sequences in the file other than these types of escape sequences. Color escape sequences are only supported when the color is changed within one line, not across lines. In other words, the beginning of each line is assumed to be normal (non-colored), regardless of any escape sequences in previous lines. For the purpose of keeping track of screen appearance, these escape sequences are assumed to not move the cursor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
## create a long file with 256 lines with different colors > myfile for fgbg in 38 48 ; do # Foreground / Background for color in {0..255} ; do # Colors # Display the color printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color >> myfile echo >> myfile done echo >> myfile done ## default less myfile ## output not color coded ## less -r or --raw-control-chars option less -r myfile ## output is color coded ## less -R or --RAW-CONTROL-CHARS option less -R myfile ## output is color coded rm myfile |