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?


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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