wc(1)
Count lines, words, and characters in files or standard input.
Synopsis
wc [OPTION]... [FILE]...Description
The wc command counts newlines, words, and bytes (or characters) in one or more files, or reads from standard input if no file is specified. By default, it displays all three counts plus the filename.
A word is defined as a string of characters delimited by whitespace (spaces, tabs, or newlines). Lines are counted by the number of newline characters encountered.
Common options
| Flag | What it does |
|---|---|
-l | Print only the newline (line) count |
-w | Print only the word count |
-c | Print only the byte count |
-m | Print only the character count (differs from -c for multibyte chars) |
-L | Print the length of the longest line |
--files0-from=FILE | Read filenames from FILE, one per line, null-terminated |
Examples
Show line, word, and byte counts for file.txt
wc file.txtCount total lines across all .log files
wc -l *.logCount words in file.txt using stdin
cat file.txt | wc -wShow the length of the longest line in file.txt
wc -L file.txtCount running processes (including header)
ps aux | wc -lCount total lines of code in all Python files
find . -name '*.py' | xargs wc -lShow byte count (useful for binary files)
wc -c file.txtShow counts for each file plus a total line
wc file1.txt file2.txt file3.txt