Linux command
wc 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Count lines, words, and bytes
wc [file]
Count only lines
wc -l [file]
Count only words
wc -w [file]
Count only characters
wc -m [file]
Count only bytes
wc -c [file]
Count lines in command output
[command] | wc -l
Count files in a directory
ls | wc -l
Count longest line length
wc -L [file]
说明
wc (word count) prints newline, word, and byte counts for each file. With multiple files, it also prints totals. With no files or stdin, it reads standard input. A word is defined as a sequence of non-whitespace characters delimited by whitespace or line boundaries. This matches most intuitive definitions of "word." The default output shows lines, words, and bytes in that order. Options select which counts to display; if none are specified, all three are shown. wc -l is extremely common for counting items in pipelines, such as counting files, matches, or log entries.
参数
- -l, --lines
- Print line count
- -w, --words
- Print word count
- -c, --bytes
- Print byte count
- -m, --chars
- Print character count
- -L, --max-line-length
- Print length of longest line
- --files0-from=_F_
- Read filenames from file F (NUL-terminated)
- --total=_when_
- When to print total (auto, always, only, never)
FAQ
What is the wc command used for?
wc (word count) prints newline, word, and byte counts for each file. With multiple files, it also prints totals. With no files or stdin, it reads standard input. A word is defined as a sequence of non-whitespace characters delimited by whitespace or line boundaries. This matches most intuitive definitions of "word." The default output shows lines, words, and bytes in that order. Options select which counts to display; if none are specified, all three are shown. wc -l is extremely common for counting items in pipelines, such as counting files, matches, or log entries.
How do I run a basic wc example?
Run `wc [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -l, --lines do in wc?
Print line count