Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 5 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
add comment

Your Answer

 
discard

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.