1. Man手册

WC(1) User Commands WC(1)
NAME
wc - print newline, word, and byte counts for each file
SYNOPSIS
wc [OPTION]… [FILE]…
wc [OPTION]… —files0-from=F
DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is
specified. With no FILE, or when FILE is -, read 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, always in the following order: newline, word, character, byte, maximum line
length.
-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 this help and exit
—version
output version information and exit

2. 命令常用选项方式及组合

2.1 基本组合

  • wc file

    1. # wc input.txt
    2. 4 7 40 input.txt
    3. 4 - lines
    4. 7 - words
    5. 40 - characters equavilent to '-m'
  • wc -c/-m/-l/-w file

  • wc -L

2.2 多个输入file

  1. # wc input.txt input.txt
  2. 4 7 40 input.txt
  3. 4 7 40 input.txt
  4. 8 14 80 total

2.3 从文件或stdin中读取多个文件名选项 —files0-from=F

--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.

--files0-from=F 选项需要依赖 NUL 字符帮助识别,无论输入是file F还是stdin.

NUL 字符的输出方式:

  1. Ctrl+V + Ctrl+Shift+@

StackOverflow上输出 NUL 的方式有具体解答,以及在StackOverflow上的这个问题地址及解答.

  1. find 命令的 -print0 选项

实际使用方式展示

  1. # way1
  2. echo "abc def" > input1.txt
  3. echo "ghi jkl" > input2.txt
  4. find . -name "input*.txt" -print0 > name.txt
  5. wc --files0-from=name.txt
  6. 1 2 8 ./input1.txt
  7. 1 2 8 ./input2.txt
  8. 2 4 16 total
  9. # way2
  10. wc --files0-from=-
  11. input1.txt^@input2.txt^@
  12. 1 2 8 input1.txt
  13. 1 2 8 input2.txt