2

I instinctively type less -R <file> whenever I want to view a file that might contain ansi escape codes (particularly for color).

Sometimes if I'm using less in a long pipeline though I forget the -R and can't easily go back and fix it without running the command again.

Do any of the common varieties of less (GNU or otherwise) expose the ability to switch between "raw" character mode and non-raw while the program is running?

4

The command inside less is -R. Yes, exactly like the option on the command line.

- Followed by one of the command line option letters, this will change the setting of that option and print a message describing the new setting. If a ^P (CONTROL-P) is entered immediately after the dash, the setting of the option is changed but no message is printed. If the option letter has a numeric value (such as -b or -h), or a string value (such as -P or -t), a new value may be entered after the option letter. If no new value is entered, a message describing the current setting is printed and nothing is changed.

So by repeating -R you will toggle displaying control characters (you may need to hit enter after each command).

For long format options you have -- and -+/--+ resets short/long options to their default values. There are more similar commands: man less is your friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.