在 Mac OS X 上批量运行 HTML Tidy?

And*_*son 4 html bash shell shell-script macos

我想对位于文件夹和子文件夹中的大量文件运行 HTML Tidy。我可以在终端中使用以下命令在单个文件上运行它:

tidy -f errors.txt -m -utf8 -i sample.html
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能运行它指定一个根文件夹并让它遍历那里的每个 html 文件,然后在每个子文件夹上做同样的事情?

Dan*_*eck 9

使用find.

find /path/to/folder -type f -name "*.html" -exec tidy -f errors.txt -m -utf8 -i {} \;
Run Code Online (Sandbox Code Playgroud)

这将在指定文件夹中的tidy所有.html文件上运行:

  • -type f匹配所有文件(而不是文件夹、符号链接等)
  • -name "*.html"匹配所有带.html扩展名的文件
  • -exec tidy -f errors.txt -m -utf8 -i {} \;运行指定的tidy命令行,并在{}. \;find终止此命令所必需的。