The wc command
print newline, word, and byte counts for each file 12 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Options in the examples
-l, --lines- print the newline counts
-w, --words- print the word counts
-c, --bytes- print the byte counts
-m, --chars- print the character counts
Examples
wc /etc/passwd
wc -l /etc/passwdLine count only
wc -w file.txtWord count only
wc -c file.txtCharacter/byte count
wc -m file.txtCharacter count (multibyte aware)
wc -l *.txtCount lines in all .txt files
ls /etc | wc -lHow many files in /etc?
cat file.txt | wc -wCount words via pipe
ps aux | grep nginx | wc -lCount nginx processes
wc -l < ~/logs/access.logHow many lines = how many requests
awk '$9 == 404' ~/logs/access.log | wc -lOnly the lines whose 9th field is 404
journalctl -u sshd -p err | wc -l