wc
The wc (word count) command prints the number of newlines, words, and bytes for each given file. If multiple files are specified, it also prints a total line.
Basic Syntax
wc [OPTION]... [FILE]...
Common Options
| Option | Description |
|---|---|
-l, --lines | Print the newline counts. |
-w, --words | Print the word counts. |
-c, --bytes | Print the byte counts. |
-m, --chars | Print the character counts. |
Real-world Examples
-
Count lines, words, and bytes in a file:
wc document.txt -
Count only the number of lines:
wc -l file.txt -
Count the number of files in a directory:
ls -1 | wc -l -
Count words in a string using standard input:
echo "Hello world" | wc -w