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?

link|improve this question
feedback

1 Answer

up vote 2 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.
link|improve this answer
Thanks, worked perfectly! – Anders Svensson Jan 7 at 11:15
feedback

Your Answer

 
or
required, but never shown

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