wc
EE 发表于 2020-08-21 15:55浏览次数:
在像 Unix 一样的操作系统上,wc命令计算每个输入文件的单词、新行或字节,并输出结果。
On Unix-like operating systems, the wc command counts the words, newlines, or bytes of each input file, and outputs the result.
目录:
1 wc 运行系统环境
2 wc 说明
3 wc 语法
4 wc 例子
wc 运行系统环境
wc 说明
wc打印每个 FILE 的符行、单词和字节计数,如果指定了多个FILE,则打印总计。没有文件,或当文件是破折号("-"),wc操作的标准输入。(单词是按空格分隔的非零长度字符序列。
以下选项可用于选择打印的计数。计数始终按以下顺序排列:单词,字符,字节,最大行长。
wc prints newline, word, and byte counts for each FILE, and a total if more than one FILE is specified. With no FILE, or when FILE is a dash ("-"), wc operates on standard input. (A word is a non-zero-length sequence of characters delimited by white space.)
The options below may be used to select which counts are printed. Counts are always in the following order: newline, word, character, byte, maximum line length.
wc 语法
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
Options
-c, --bytes
|
打印字节计数。
|
-m, --chars
|
打印字符计数。
|
-l, --lines
|
打印新行计数。
|
--files0-from=F
|
从文件 F 中由NUL终止的名称指定的文件读取输入;如果F是 "-" 然后从标准输入读取名称。
|
-L, --max-line-length
|
最大线长度 打印最长行的长度。
|
-w, --words
|
打印单词计数。
|
--help
|
显示帮助消息,然后退出。
|
--version
|
输出版本信息,然后退出。
|
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
Options
-c, --bytes
|
print the byte counts.
|
-m, --chars
|
print the character counts.
|
-l, --lines
|
print the newline counts.
|
--files0-from=F
|
read input from the files specified by NUL-terminated names in file F; If F is "-" then read names from standard input.
|
-L, --max-line-length
|
print the length of the longest line.
|
-w, --words
|
print the word counts.
|
--help
|
display a help message, and exit.
|
--version
|
output version information, and exit.
|
wc 例子
wc myfile.txt
显示有关文件myfile.txt 的信息。输出将类似于以下内容:
5 13 57 myfile.txt
其中5是行数,13是单词数,57是字符数。
ls -1 | wc -l
此命令返回当前目录中的对象数。它使用ls命令生成目录内容的单列 (-1) 列表,每个对象输出一行;此输出通过管道到 wc,它计算行 (-l),并返回该数字。
wc myfile.txt
Displays information about the file myfile.txt. Output will resemble the following:
5 13 57 myfile.txt
Where 5 is the number of lines, 13 is the number of words, and 57 is the number of characters.
ls -1 | wc -l
This command returns the number of objects in the current directory. It uses the ls command to produce a single-column (-1) listing of the directory contents, which outputs one line per object; this output is piped to wc, which counts the lines (-l), and returns that number.