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

0
5
Asked By MellowPine42 On

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?

2 Answers

Answered By CedarOrbit3 On

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`.

Answered By QuartzHarbor7 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.