【问题标题】:How to write the wc's stdout into a file?如何将 wc 的标准输出写入文件?
【发布时间】:2020-04-06 11:45:19
【问题描述】:

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

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

我想将突出显示写入文件。

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

遇到问题:

wc: .: Is a directory

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

【问题讨论】:

  • in current directory - 不, find 递归工作,所以它也包括下面的所有目录。它还输出目录,这就是你看到的原因。 .: Is a directory。因为.是一个目录。
  • 可以查看原markdownhere。
  • 写输出不是问题; xargs 在非常规文件上调用 wc 是。

标签: bash stdout xargs


【解决方案1】:

为什么是-name '*.*'?那不会找到每个文件,而是会找到目录。您需要使用-type f,并且比将结果传送到xargs 更好的是使用-exec:

find . -type f -maxdepth 1 -exec wc -c {} + > /tmp/record.txt

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

【讨论】:

    【解决方案2】:

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

    find -name '.' 只返回.

    【讨论】:

      【解决方案3】:

      仅过滤文件,如果您只想要文件。

      find -type f
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-01
        • 2014-07-03
        • 2013-03-18
        • 2018-12-07
        • 2011-04-09
        • 1970-01-01
        • 2015-02-08
        相关资源
        最近更新 更多