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

> At leat one other (Linux) doesn't really use "extensions" and instead relies on magic headers inside the files to determine the format.

mostly for executable files.

I doubt many Linux apps look inside a .py file to see if it's actually a JPEG they should build a thumbnail for.



Your doubts are incorrect. There's a fairly standard way of extracting the file type out of files on linux, which relies on a mix of extensions and magic bytes. Here's where you can start to read about this:

https://wiki.archlinux.org/title/XDG_MIME_Applications

A lot of apps implement this (including most file managers)


I'm a little surprised that that link doesn't go to libmagic[1]. No doubt XDG_MIME is an important spec for desktop file detection, but I think libmagic and the magic database that underpins it are more fundamental to filetype detection in general.

It's also one of my favorite oddities on Linux. If you're a Windows user the idea of a database of signatures for filetypes that exists outside the application that "owns" a file type is novel and weird.

[1]: https://man7.org/linux/man-pages/man3/libmagic.3.html


libmagic maintains its own separate database from xdg. XDG db is meant from the ground up to have other apps add to it etc… so that one is the one apps use as a library usually, if they want to integrate nicely and correctly with other installed apps. libmagic is the hacking of the two :)




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

Search: