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?

  • Looking for another answer. I have a log file that cat somefile shows as ASCII, but less somefile says may be binary and displays as such. echo $LESSOPEN is empty and less -L doesn't help. Commented May 13, 2014 at 15:09
  • 2
    @NathanLong This would probably be acceptable to open a new question on since the solution here does not solve your problem (just make sure to note that). However when you say "may be binary and displays as such", are you saying it display a hex representation of the data, or you see the raw binary data (as all the weird symbols and such)?
    – phemmer
    Commented May 14, 2014 at 4:39
  • What is LHS? It is new to me.
    – dfc
    Commented May 17, 2014 at 3:37
  • 1
    @dfc left-hand side. Commented May 18, 2014 at 14:21

2 Answers 2


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.

  • I was using less into a script of a service and it wont work until i use /usr/bin/lesspipe
    – Juan
    Commented Oct 4, 2022 at 17:07

For the case of LESSOPEN not being the issue. The following less options could be tried:

  1. -f or --force: Besides allowing non-regular files to be opened, it "also suppresses the warning message when a binary file is opened".
  2. -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.
  3. -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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .