wc
In this page:
wc
wc counts lines (-l), words (-w), and characters/bytes (-c) in its input. It's often placed at the end of a pipeline to summarize how much data made it through previous filtering steps. Running it with no flags prints all three counts together.
Note: command | wc -l is the standard idiom for counting how many lines a command produced.
Example: wc
#!/bin/bash
printf "one\ntwo\nthree\n" > words.txt
echo "Lines: $(wc -l < words.txt)"
echo "Words: $(wc -w < words.txt)"
echo "Characters: $(wc -c < words.txt)"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: