Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

mv image.png program.exe

mv program.exe sound.mp3

mv sound.mp3 text.pdf

Same file, always a PNG despite the extensions I can attach to it.



Sure. But I think of the file extension as a way to tell the OS which program I want a file to open with. In Windows when I see a .mp3 file I know which program will open when I double click on it. In Linux it's a mystery. I like my computer to behave in a predictable manner.

In Windows extensions have a meaning. In Linux, why even bother having extensions? In neither OS does the extension tell you about the content of the file. But on Windows the extension does tell you something useful about how the OS interacts with the file.


Out of curiosity I checked what Files (the desktop app) and file (the CLI tool) do in Ubuntu 20.04.

Files says that image.png is a PNG image

  $ file image.png
  image.png: PNG image data, 965 x 720, 8-bit/color RGB, non-interlaced

  $ mv image.png program.exe
According to Files it's a DOS/Windows executable. If I try to open it from there it opens Archvie Manager and displays an error dialog. And yet

  $ file program.exe 
  program.exe: PNG image data, 965 x 720, 8-bit/color RGB, non-interlaced
  $ eog program.exe
It loses bash autocompletion on program.exe but eog opens the image.

  $ mv program.exe sound.mp3
Files reports it as MP3 audio. It opens in the sound player program (it has no nome on screen) and does nothing. Of course file correctly identifies the file as PNG. eog sound.mp3 works.

  $ mv sound.mp3 text.pdf
Files says it's a PDF document and opens it in evince, which fails with an error message. eog text.pdf works

A suggestion to Files' authors: check the magic file definition, not the extension, especially when opening files.

What I use extensions for: to remember what a file is, by the name of it when doing ls in the terminal. The extension is more to help me than the OS. I open most of the files I work with by the command line, not in Files. Another reason is that if I send the file to somebody else I want to make it easy for them. So screenshot-2020-11-16_1000.png and not screenshot-2020-11-16_1000 which maybe breaks some of their tools. Third reason: some files must have an extension: header.h, program.c, program.o, program and not header and code, code, code :-)

And yes, programs in *NIX never had extensions. So ls / and not ls.exe /


> In Linux, why even bother having extensions

While the file extension can be lying maliciously or can be just plain incorrect in 1% cases, its informative for the user in the other 99% cases


I agree with you. But pmontra seems to operate differently than that, and have files with mismatching extensions. In that case the extensions tell you something on Windows but not on Linux.


I don't mismatch extensions because I don't want to play tricks to me in the future :-) Sometimes I don't add extensions, usually on plain text files.


> In Linux it's a mystery. I like my computer to behave in a predictable manner.

You're not really talking about Linux. You're talking about mime types and xdg-open, the de-facto default way Linux desktop environments (not to be confused with distros) handle default applications. You mentioned double clicking so I'm going to assume you were talking about it in the context of a GUI DE opening files from a file manager or the desktop.

xdg-open is configurable and even completely replaceable. For example, I have it replaced with mimeo, which I have a couple hardset rules based on extensions. Any time I don't like its default behavior, I'll add 2 lines to the config file to specify what I want. I personally don't like configuring mime types and stuff itself. It's incredibly predictable because for example I just tell mimeo that anything that ends with pdf should be opened with zathura. I find that Linux tends to be way less mysterious since it's so open and transparent and configurable.

But a valid complaint to this response would be that defaults matter, and that you shouldn't have to tinker to get what you want. So I think in that sense you're thinking of how KDE/GNOME handles this, which last I checked was extremely simple. You just right click a file and set the default application for opening its mimetype. Any future file of this mimetype will be opened by what you specified. And I think mimetypes are just better UX than raw extensions; it's a much better experience telling KDE to open all music files with your music app rather than specifying extensions. And various applications come with .desktop files that let you know what they can handle. So you get a nice list of relevant applications but you can still tell it to open it in whatever you want. Meanwhile in Windows the default behavior is to hide file extensions which I think is actually the worst of both worlds. Using file extensions to inform default applications while hiding them. I find that to be more mysterious.

> In Windows extensions have a meaning. In Linux, why even bother having extensions? In neither OS does the extension tell you about the content of the file. But on Windows the extension does tell you something useful about how the OS interacts with the file.

Again, "Linux" is not a monolith (yes the kernel is monolithic, but you know what I mean) that you can compare directly to Windows. Windows basically has a mime types system but worse (less intelligent with clunkier UI and legacy defaults), and there's nothing you can do to change it. On Linux it depends entirely on what you have setup. For example, for a long time I just never had it set up. There was nothing to "double-click" to begin with, and if I wanted to for example open an image file with my image viewer, I would just type out `imv bruh.png`.

What you're actually debating is xdg-open vs. whatever it's called in Windows. I personally kind of agree with you so I don't use xdg-open. But I'm still using Linux.


>You're not really talking about Linux. You're talking about mime types and xdg-open, the de-facto default way Linux desktop environments (not to be confused with distros) handle default applications.

Yes, but the github page this post is about is making that same mistake.

> Meanwhile in Windows the default behavior is to hide file extensions which I think is actually the worst of both worlds.

Oh yes, terrible, I can't believe I actually forgot about that. I've modified that on every Windows computer I use.

Thanks for the info! I'll keep this in mind when I eventually switch to Linux like I've been meaning to for a while...


Yeah, not blaming you at all for the common misconception. I'm just glad you got something out of my wall of text.

If you ever make the switch, definitely check out the Arch Linux wiki even if you never use Arch: https://wiki.archlinux.org/index.php/Default_applications




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: