Mime Types
Pythonic Magic Mime
Here is a pythonic way to check what a file is using magic mime types:
import sys
import magic # python -m pip install python-magic
filename = sys.argv[1]
try with open(filename) as fh:
blob = open(filename, 'rb').read()
m = magic.Magic(mime_encoding=True)
encoding = m.from_buffer(blob)
print(encoding)
except IOError as err:
print(err)
Linux file type
Standard Linux has a tool called “file” which also helps identify what a file is.
(1:907)# file id_ed25519.pub
id_ed25519.pub: OpenSSH ED25519 public key
(1:908)# file /usr/bin/whoami
/usr/bin/whoami: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=7516179fdf8ec3353673a8abcfdf0b60ec2c3b8f, stripped