带查找的文件管道

File piping with find

当我 运行 命令 cd dir && find . -name "*.html" 它完美地显示所有 html 文件,包括子目录中的 html 文件。但是当我 运行 时,命令 cd dir && find . -name "*.html" | for f in *.html; do "action"; done 只会在当前目录中为我循环,但不会更改子目录中的 html 文件。我尝试将查找合并到 for 循环中,但只得到一条错误消息。

你可以改写为

cd dir && find . -name "*.html" | while read f; do "action"; done

当你

... for f in *.html; ...

你实际上列出了当前目录中的 html 文件,实际上等同于 ls *.html,并且没有过滤从管道接收的列表(被忽略)