What it does
wc (word count) prints, for each file: the number of lines, words and bytes. With options you choose one count. wc -l is used all the time to count lines of a file or results of a command.
How to write it
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=FOptions 9
Most used
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1Lines, words and bytes
wc /etc/passwd 45 95 2512 /etc/passwdThree numbers: lines, words, bytes.
2Count lines only
wc -l /etc/passwd 45 /etc/passwdEach line is one account.
3Count results of a command
ls /etc | wc -lHow many entries in /etc.
4Only the number, without the file name
wc -l < /etc/passwd 45Input from a redirect has no name. Good in scripts.
5Count running processes
ps -e --no-headers | wc -lHow many processes run now.
6Count failed SSH logins today
journalctl -u sshd --since today | grep -c "Failed password"grep -ccounts directly; same asgrep … | wc -l.7Count lines of all scripts in a folder
wc -l *.shEach file plus a total line.
8Check the longest line of a file
wc -L config.yamlSome tools have line length limits.
9Count characters in UTF-8 text
echo -n "سلام" | wc -m 4-cwould count 8 bytes;-mcounts 4 characters.10Compare the size of two lists
wc -l before.txt after.txtQuick check after a cleanup or an import.
11Alert when a log grows too fast
A tiny monitoring check.
Nothing matches this filter.
Watch out
- The last line of a file without a new line is not counted by
-l.
Tips to remember
wc -l= how many lines.wc -l < file= number only.