我想在位于文件夹和子文件夹中的大量文件上运行HTML Tidy。我可以在终端中使用以下命令在单个文件上运行它:
tidy -f errors.txt -m -utf8 -i sample.html
但是如何运行它来指定根文件夹并让它遍历那里的每个html文件,然后在每个子文件夹上执行相同的操作?
我想在位于文件夹和子文件夹中的大量文件上运行HTML Tidy。我可以在终端中使用以下命令在单个文件上运行它:
tidy -f errors.txt -m -utf8 -i sample.html
但是如何运行它来指定根文件夹并让它遍历那里的每个html文件,然后在每个子文件夹上执行相同的操作?
Answers:
使用 find。
find /path/to/folder -type f -name "*.html" -exec tidy -f errors.txt -m -utf8 -i {} \;
这将运行 tidy 所有 .html 指定文件夹中的文件:
-type f 匹配所有 档 (与文件夹,符号链接等相对) -name "*.html" 匹配所有文件 .html 延期 -exec tidy -f errors.txt -m -utf8 -i {} \; 运行指定的 tidy 命令行,插入完整文件路径 {}。 \; 是必需的 find 终止此命令