2

I am struggling with the following issue. I have a Unix directory containing ~ 60K files and I would like to be able to count all the words in each file and output a list with each count along with its corresponding filename.

4

2 回答 2

8

这是find和的工作wc

find . -maxdepth 1 -type f -exec wc -w {} \;

这将执行当前工作目录find(_-type f.-maxdepth 1-exec [...] \;wc -w{}

wc默认情况下打印文件中的换行符、单词和字节数,-w指定它应该只打印字数。

于 2013-09-02T18:38:56.843 回答
0

从当前文件夹获取结果的几个更方便的命令

获取文件类型为 java 的所有文件中的单词

find . -name '*.java' | xargs grep 'word'

在所有文件中获取单词

find . -type f | xargs grep 'word'
于 2016-04-25T07:28:45.620 回答