Is there a mac terminal command to change all .html files to .txt including the files in sub folders too?

  • I got it but how do we do this to an entire folder! Not logical to enter 1000's of file names.
    – Adrien
    Oct 11, 2015 at 6:32
  • you cd to the folder first. tbh, you could have done it by now, using something like Quick File Renamer Lite or a dozen freeware alternatives
    – Tetsujin
    Oct 11, 2015 at 6:36
  • 1
    I'd forgotten that's now included in Yosemite. I've had it for years as a 3rd party add-in service. So why not use that? Does it have to be done in terminal? Otherwise it's just Replace Text > .html > .txt Finder prefs > advanced if you want to switch off the change extension warning.
    – Tetsujin
    Oct 11, 2015 at 6:57
  • 4
    Do you just want to change the extension or do you want to remove all HTML formatting as well?
    – nohillside
    Oct 11, 2015 at 7:15

3 Answers 3


I guess actually you just want to rename them. Run the following from inside the folder. If you do not trust the command, add echo before mv to see what it would do.

find . -type f -name "*.html" -exec bash -c "mv {} \`dirname {}\`/\`basename -s.html {}\`.txt" \;

This does the following:

  1. Looks up every file (-type f) in the current folder (.) whose name is ends with ".html" (-name "*.html")
  2. It than finds out the path of the file (dirname), adds a slash (/) and the name of the original file without the ".html" suffix (basename -s.html) and adds a ".txt" suffix.
  3. Then it renames the original file (mv).

Actually, the ` ` notation for using a programs output as part of a command is deprecated. $() should be used instead, but in the case of find the backticks are easier to use.



You can use rename which you can install using brew.

Install rename using brew: brew install rename

Rename files using rename:

rename -s .html .txt *


for file in *.html; do
   mv "${file}" "${file%.html}".txt

This 'for loop' is just one way to do it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .