Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run HTML Tidy on a large number of files located in folders and subfolders. I can use the following command in Terminal to run it on a single file:

tidy -f errors.txt -m -utf8 -i sample.html

But how can I run it specifying a root folder and have it go through each of the html files in there, and then do the same on each subfolder?

share|improve this question
up vote 7 down vote accepted

Use find.

find /path/to/folder -type f -name "*.html" -exec tidy -f errors.txt -m -utf8 -i {} \;

This will run tidy on all .html files in the specified folder:

  • -type f matches all files (as opposed to folders, symbolic links, etc.)
  • -name "*.html" matches all files with .html extension
  • -exec tidy -f errors.txt -m -utf8 -i {} \; runs the specified tidy command line, with the full file path inserted at {}. \; is required by find to terminate this command.
share|improve this answer
Thanks, worked perfectly! – Anders Svensson Jan 7 '12 at 11:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.