Online Linux Terminal Logo
OnlineLinuxTerminal
文本处理CLI Manual

$wc

Print newline, word, and byte counts for files.

命令语法POSIX Standard
wc [OPTIONS] [FILE...]
Linux 社区2.4k 在线

与真实 Linux 用户交流,学习常用命令并免费获取精美速查表 PDF。

在交互式终端沙盒中实时运行

无需安装的客户端实时仿真环境。

在全屏终端工作区中打开 ↗
bash — terminal

概述与工作原理

`wc` (Word Count) reads files or standard input and computes statistics including line count (`-l`), word count (`-w`), and byte count (`-c`). It is widely used in shell pipelines to count query results or filter matches (e.g., `grep ... | wc -l`).

常用参数与选项说明

Flag / OptionDescription
-lCount and print total newline line counts.
-wCount and print total words.
-cCount and print total bytes.
-mCount and print total characters.

实际生产案例与代码范例

#1Count total lines in a file
wc -l welcome.txt

Outputs the line count for welcome.txt.

#2Count matching error occurrences in logs
grep "error" /var/log/syslog | wc -l

Pipes grep output into wc -l to get the exact integer count.