This is a question regarding Unix shell scripting (any shell), but any other "standard" scripting language solution would also be appreciated:
I have a directory full of files where the filenames are hash values like this:
fd73d0cf8ee68073dce270cf7e770b97 fec8047a9186fdcc98fdbfc0ea6075ee
These files have different original file types such as png, zip, doc, pdf etc.
Can anybody provide a script that would rename the files so they get their appropriate file extension, probably based on the output of the file command?
Answer:
J.F. Sebastian’s script will work for both ouput of the filenames as well as the actual renaming.
Here’s mimetypes’ version:
Example:
Following @Phil H’s response that follows @csl’ response:
Here’s a snippet for old python’s versions (not tested):
It should work on Python 2.3.5 (I guess).