githubEdit

rectangle-terminalwc

πŸ”’ wc Command in Linux

The 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

Count non-empty lines in a file

Count how many .txt files contain the word "error"

Count total words across multiple .md files

Count active processes

Count users currently logged in

Count open network connections


Last updated