Beginner · 4 min · practise every command in the built-in terminal

wc — Word Count

wc counts lines, words, and characters in files.

Basic usage

wc /etc/passwd

Output: 45 88 2512 /etc/passwd Meaning: 45 lines, 88 words, 2512 bytes

Specific counts

wc -l /etc/passwd    # Line count only
wc -w file.txt       # Word count only
wc -c file.txt       # Character/byte count
wc -m file.txt       # Character count (multibyte aware)

Multiple files

wc -l *.txt          # Count lines in all .txt files

Combined with pipes

ls /etc | wc -l      # How many files in /etc?
cat file.txt | wc -w # Count words via pipe

Practice tasks

  1. Count how many lines are in /etc/passwd
  2. Count how many files are in /etc using ls and wc
  3. Count how many words are in README.txt
  4. Count how many characters/bytes are in README.txt

Commands in this lesson

Reading Files