Why does `less` treat a `.jpg` file as an image when Linux ignores extensions?

August 27, 2026 2 answers
Asked by MellowPine42
I'm trying to understand how Linux handles file extensions. I created a file with `touch banana.jpg`, then added plain text to it with `nano`. `cat banana.jpg` shows the text normally, but running `less banana.jpg` displays a message such as "No identify available" and suggests installing ImageMagick to browse images. Why is `less` treating the file as an image, and how can I make it display the file contents as ordinary text?

Answers

QuartzHarbor7
Linux itself generally doesnโ€™t use the `.jpg` suffix to determine a fileโ€™s type. However, many systems configure `less` to use a helper called `lesspipe`. The `LESSOPEN` environment variable points to that helper, which may inspect the filename extension and invoke programs for images, archives, compressed files, and other formats. This behavior depends on the distribution and its `less` configuration, so another system may display the text normally.

MellowPine42: That gives me a useful leadโ€” Iโ€™ll look into environment variables and how `LESSOPEN` is configured.

Reply to this answer
CedarOrbit3
Check whether `LESSOPEN` is set with `env | grep LESSOPEN`. You can bypass the configured preprocessor for one command with `less -L banana.jpg`, or disable it in the current shell with `unset LESSOPEN`. After that, `less` should read the file directly and show the text, regardless of its `.jpg` name. The exact result can vary between distributions because not every system enables `lesspipe`.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions