Text
wc
Count lines, words, bytes, and characters.
textcountlineswordsbytes
Additional Notes
wc counts text. The name means word count, but it can also count lines, bytes, and characters.
It is useful in scripts, pipelines, and quick checks such as counting log lines or files returned by another command.
Syntax
wc [options] [file...]
Parameters
options: Flags that change howwcbehaves.file: Text file to read or process.
Common Options
-l,--lines: Count lines.-w,--words: Count words.-c,--bytes: Count bytes.-m,--chars: Count characters.-L,--max-line-length: Show length of the longest line.
Examples
wc file.txt
Show lines, words, bytes, and filename.
wc -l app.log
Count lines in a file.
grep "error" app.log | wc -l
Count matching log lines.
find . -type f | wc -l
Count files under the current directory.
wc -L file.txt
Show the longest line length.
Practical Notes
wc -lcounts newline characters, which usually means lines.- When reading from a pipe,
wcdoes not print a filename. - Use
wc -cfor byte size andwc -mfor character count. - For disk usage, use
du, notwc.