Code, Computers & Random Junk

Find and Rename With `find’

Between 2 beta updates of Firefox, the UnMHT add-on broke, so I had to use the other one instead. Now when it started to work again I needed to rename to webarchives I had made during that time - since the file extensions differ a little bit.

  • UnMHT: Saves the archive with an .mht extenstion, while
  • Mozilla Archive Format archives ends with .html.mht

Since they’re spread out, I used find to both find and rename them.


Here are 2 ways to find the files:

find . -type f -name "*.html.mht" -exec echo {} \;

find . -type f -name "*.html.mht" | while read i ; do echo "$i"; done


And this is what I used to renamed them:

find . -type f -name "*.html.mht" | while read i ; do mv -f "${i}" "${i//html./}"; done

…using a little bit “parameter expansion” there at the end. +1

One could’ve used -exec or xargs, but I decided to go with: find, pipe and then while read…