
How does ‘file’ determine MIME Type?Īnswers to this question has some useful information: And I am going to uncover that today, starting with the file utility which seems to have different answers to different programs. Maybe echo writes the mimetype as a metadata onto the disk because echo is a system utility and it knows to do that and in Python the user (me) doesn’t know how to? Clearly the operating system utilities are a cabal of some forbidden knowledge. What? file doesn’t recognise file extensions? The OS conspiracy theory Some_file_2.txt: application/octet-stream Don’t the OSes warn when we touch the extension part of the files while renaming, all the time? So, how does file utility do this on a files without any extension?

I thought operating systems usually use the file extension to decide the file type, by extension the mime type.After all, MIME stands for Multipurpose Internet Mail Extensions I thought MIME Type is only relevant in the context of web server and clients. I didn’t know the file utility can be used to get the mime-type of the file.When I saw this question on StackOverflow, I was really stumped due to the following reasons: What’s the difference? For the impatientĮcho adds a new line to file which tells the file utility it is a text file.


But, when you do the same in Python byĪnd then check the MIME type it would say application/octet-stream. When you do echo "x" > my_file and then check its MIME type using file -mime-type my_file it would say text/plain.
