如何将 wc 的标准输出写入文件?

How to write the wc's stdout into a file?

下面的命令将显示当前目录中每个文件包含多少个字符。

find  -name '*.*' |xargs  wc -c  

我想把突出的写到一个文件中。

find  -name '*.*' |xargs  wc -c  > /tmp/record.txt

遇到问题:

wc: .: Is a directory

如何将所有的标准输出写入一个文件?

我想你的意思可能是 find |xargs wc -c

find -name '.'只是returns.

如果只需要文件,则只过滤文件。

find -type f

为什么-name '*.*'?那不会找到每个文件,而是会找到目录。您需要使用 -type f,并且使用 -exec:

比将结果通过管道传输到 xargs 更好
find . -type f -maxdepth 1 -exec wc -c {} + > /tmp/record.txt

-maxdepth 1 保证搜索不会深入子目录。