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?
2 Answers
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.

- 16,682
-
I was using
less
into a script of a service and it wont work until i use/usr/bin/lesspipe
– Juan Oct 04 '22 at 17:07
For the case of LESSOPEN
not being the issue. The following less
options could be tried:
-f
or--force
: Besides allowing non-regular files to be opened, it "also suppresses the warning message when a binary file is opened".-r
or--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-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.-R
or--RAW-CONTROL-CHARS
: Weaker form of-r
above, 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.

- 655
cat somefile
shows as ASCII, butless somefile
says may be binary and displays as such.echo $LESSOPEN
is empty andless -L
doesn't help. – Nathan Long May 13 '14 at 15:09