wc
🔢 wc
Command in Linux
wc
Command in LinuxThe wc
(word count) command is used to count lines, words, characters, bytes, and maximum line lengths in text files or input streams.
📋 Common Options
Option
Description
-l
Count lines
-w
Count words
-c
Count bytes
-m
Count characters (useful for multibyte text)
-L
Print length of longest line
🧪 Examples
Count Lines, Words, and Bytes in a File
wc file.txt
Output format:
<lines> <words> <bytes> file.txt
🛠 Use Cases
Check file size quickly by byte count:
wc -c filename
Count lines of code:
find . -name "*.py" | xargs wc -l
Measure log file growth:
wc -l logfile.log
🔗 More Pipe Examples
Practical combinations of wc
with other Linux commands using pipes:
Count files in a directory
ls | wc -l
Count non-empty lines in a file
grep -v '^$' file.txt | wc -l
Count how many .txt
files contain the word "error"
.txt
files contain the word "error"grep -il "error" *.txt | wc -l
Count total words across multiple .md
files
.md
filescat *.md | wc -w
Count active processes
ps aux | wc -l
Count users currently logged in
who | wc -l
Count open network connections
netstat -tun | tail -n +3 | wc -l
Last updated