How to determine the file type in Linux?

If someone sends me a document (.pdf, .doc, .xls, ppt, .ogg, mp3, png, etc.) without an extension, how can I determine the file type? The command / usr / bin / file does not always correctly guess or just say that I have a Microsoft Office document. I would like to know for sure that I can add the extension to the file name.

+3
source share
4 answers

You can come up with your own rules by adding them to / etc / magic

man file for more details. It is always difficult to understand this correctly, I had a reasonable success.

+7
source

Try mimetype (1).

For Perl, see File :: MimeInfo .

+3
+1

, , .

File::MimeInfo MimeInfo, . - .

File::Type, , , , , script 'if'. , , "", .

The best thing you can do with unknown file types is to try to crack them using the hex editor or run them through the "lines" and see if you recognize anything. If you decide how to identify the file, you can go as a File :: Type solution , because as far as I can figure it out, it is at least easy to extend.

+1
source

Source: https://habr.com/ru/post/1704594/


All Articles