Count lines, words, characters, or bytes in files.
low risk
wc (word count) counts newlines, words, characters, and bytes in files or stdin. Invaluable for quick data validation — checking how many records are in a file, confirming a log has expected line counts, or measuring output size.
| Flag | Meaning |
|---|---|
-l --lines | Count lines only |
-w --words | Count words only |
-c --bytes | Count bytes only |
-m --chars | Count characters only |
wc -l /etc/passwdCount number of user accounts · explain & risk-check →cat access.log | wc -lCount total log entries · explain & risk-check →ls *.yaml | wc -lCount YAML files in current directory · explain & risk-check →wc -c deployment.yamlCheck file size in bytes · explain & risk-check →Use `grep -c 'pattern' file` instead of `grep 'pattern' file | wc -l` — it's faster and more efficient for counting matching lines.
Reference text is hand-written and may be incomplete — check man wc for your version. Test destructive commands on a non-production system first.