text
wc
Counts lines, words, characters, and bytes in files or stdin. Frequently used at the end of pipelines to size results.
wc [OPTION]... [FILE]... Common flags
| Flag | Purpose |
|---|---|
| -l | Print the newline count |
| -w | Print the word count |
| -c | Print the byte count |
| -m | Print the character count |
| -L | Print the length of the longest line |
Examples
wc -l *.py Count lines in every Python file plus a total
grep ERROR app.log | wc -l Count matching lines in a pipeline
wc -c file.bin Report byte size of a binary
wc -L source.txt Find the longest line's width
Gotcha
-c counts bytes, -m counts characters -- they diverge for multibyte encodings like UTF-8.
Related commands
grep
Searches text for lines matching a regular expression. Central to log analysis and pipeline filtering.
sort
Sorts lines of text. Supports numeric, human-numeric, reverse, unique, and keyed sorting.
cut
Extracts sections from each input line by byte, character, or delimited field. Handy for pulling columns out of CSV or colon-delimited files.
cat
Concatenates files and prints them to standard output. Also useful as a simple viewer or to feed content into pipelines.
sed
Stream editor that applies a small program to each line of input. Widely used for search-and-replace and inline file edits.