Linux wc Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux wc Guide
Complete beginner-friendly guide to wc on Linux, covering Arch Linux, CachyOS, and other distributions including counting lines, words, characters, and file statistics.
Table of Contents
Understanding wc
What is wc?
wc (word count) counts lines, words, and characters.
Uses:
- Count lines: Number of lines
- Count words: Number of words
- Count characters: Number of characters
- File statistics: Get file info
Why it matters:
- Text analysis: Analyze text files
- Scripts: Count in scripts
- File info: Quick file statistics
wc Basics
Count Everything
Full count:
# Count lines, words, characters
wc file.txt
# Output: lines words characters filename
Multiple Files
Count several:
# Count multiple files
wc file1.txt file2.txt
# Shows each file and total
Counting Options
Count Lines
Line count:
# Count lines only
wc -l file.txt
# Or
cat file.txt | wc -l
Count Words
Word count:
# Count words only
wc -w file.txt
# Word count
Count Characters
Character count:
# Count characters
wc -c file.txt
# Byte count
Count Bytes
Byte count:
# Count bytes
wc -c file.txt
# Same as characters for ASCII
Practical Examples
Count Files
Directory stats:
# Count files
ls -1 | wc -l
# Number of files
Count Code Lines
Code statistics:
# Count lines in code
find . -name "*.py" -exec wc -l {} +
# Total lines in Python files
Troubleshooting
wc Not Found
Check installation:
# Check wc
which wc
# Usually in coreutils
# Install if missing
sudo pacman -S coreutils
Summary
This guide covered wc usage, counting options, and file statistics for Arch Linux, CachyOS, and other distributions.
Next Steps
- sort Guide - Text sorting
- cut Guide - Field extraction
- wc Documentation:
man wc
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.