Table of Contents
Open Table of Contents
Introduction
The wc
(word count) command is a simple yet powerful tool in Linux for counting the number of lines, words, and characters in a file or text input.
Basic Usage of wc
Syntax
The basic syntax of wc
is:
wc [options] [file...]
Example
To count the lines, words, and characters in a file:
wc file.txt
Common Use Cases
- Counting Lines: Use the
-l
option to only display the line count.wc -l file.txt
- Counting Words: Use the
-w
option to only display the word count.wc -w file.txt
Advanced wc Techniques
Counting Characters
Use the -m
option to display the character count.
wc -m file.txt
Conclusion
The wc
command is a versatile tool for quickly obtaining basic statistics about text files and input in a Linux environment.