Sometimes less wrongly recognize file as binary and tries to show hexdump on LHS (usually ones with non-alphanumeric characters but still containing printable ASCII characters). How to force it to recognize it as text?
I think you have (or your distribution has) a
LESSOPEN filter set up for
less. Try the following to tell
less to not use the filter:
less -L my_binary_file
For further exploration, also try
echo $LESSOPEN. It probably contains the name of a shell script (
/usr/bin/lesspipe for me), which you can read through to see what sort of filters there are. Also try
man less, and read the Input Preprocessor section.
For the case of
LESSOPEN not being the issue. The following
less options could be tried:
--force: Besides allowing non-regular files to be opened, it "also suppresses the warning message when a binary file is opened".
--raw-control-chars: "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
-roption 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.
--RAW-CONTROL-CHARS: Weaker form of
-rabove, only ANSI "color" escape sequences are output in "raw" form. "Unlike -r, the screen appearance is maintained correctly in most cases." This is useful if you are for example viewing a log file that uses ANSI color control sequences.
You can experiment by pressing keys - followed by r without rerunning
less. You can add these options to
LESS environment variable to make the setting permanent (e.g. by modifying your shell profile file); if your terminal can show colors I highly recommend adding
-R in your
LESS setting. You should make sure your terminal is configured to use the same character encoding as your text file.