title: Rename file while keeping the extension in Linux?
body: <p>I have a directory that contains multiple files with different extensions (pdf, doc, txt...etc).</p>
  
  <p>I'm trying to rename all files according to the directory name while keeping the file extension the same. The code below works fine if all files are PDF otherwise it will change txt file extension to pdf too.</p>
  
  <p>How can I rename files while preserving the file extension</p>
  
  <pre><code>mv "$file" "${dir}/${dir}-${count}.pdf"
  </code></pre>