title: How to add file extensions based on file type on Linux/Unix?
body: <p>This is a question regarding Unix shell scripting (any shell), but any other &quot;standard&quot; scripting language solution would also be appreciated:</p>
  <p>I have a directory full of files where the filenames are hash values like this:</p>
  <pre><code>fd73d0cf8ee68073dce270cf7e770b97
  fec8047a9186fdcc98fdbfc0ea6075ee
  </code></pre>
  <p>These files have different original file types such as png, zip, doc, pdf etc.</p>
  <p>Can anybody provide a script that would rename the files so they get their appropriate file extension, probably based on the output of the <code>file</code> command?</p>
  <h2>Answer:</h2>
  <p><a href="https://stackoverflow.com/questions/352837/how-to-add-file-extensions-based-on-file-type-on-linuxunix#352973">J.F. Sebastian's</a> script will work for both ouput of the filenames as well as the actual renaming.</p>