咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
wc命令用来打印文件的文本行数、单词数、字节数等(print the number of newlines, words, and bytes in files)。在Windows的Word中有个“字数统计”的工具,可以帮我们把选中范围的字数、字符数统计出来。Linux下的wc命令可以实现这个 功能。使用vi打开文件的时候,底下的信息也会显示行数和字节数。
(1)常用参数
格式:wc -l <file>
打印指定文件的文本行数。(l=小写L)
以下参数可组合使用。
参数:-c, --bytes
打印字节数(print the byte counts)
参数:-m, --chars
打印字符数(print the character counts)
参数:-l, --lines
打印行数(print the newline counts)
参数:-L, --max-line-length
打印最长行的长度(print the length of the longest line)
参数:-w, --words
打印单词数(print the word counts)
(2)wc命令与 ls命令搭配使用
统计当前文件夹下文件的个数
ls -l |grep "^-"|wc -l
统计当前文件夹下目录的个数
ls -l |grep "^d"|wc -l
统计当前文件夹下文件的个数,包括子文件夹里的
ls -lR|grep "^-"|wc -l
统计文件夹下目录的个数,包括子文件夹里的
ls -lR|grep "^d"|wc -l