Command Line Operations
Basic Word Count Commands
Counting Lines
To count the number of lines in a file:
wc -l filename.txt
Counting Words
To count the total number of words:
wc -w filename.txt
Counting Characters
To count the total number of characters:
wc -m filename.txt
Advanced Command Options
Option |
Description |
Example |
-l |
Count lines |
wc -l file.txt |
-w |
Count words |
wc -w file.txt |
-c |
Count bytes |
wc -c file.txt |
-L |
Longest line length |
wc -L file.txt |
Multiple File Processing
Counting in Multiple Files
Count statistics for multiple files:
wc file1.txt file2.txt file3.txt
Recursive Counting
Count files in directories:
find . -type f | xargs wc
Piping and Redirection
graph LR
A[Input] --> B{wc Command}
B --> |Pipe| C[Further Processing]
B --> |Redirect| D[Output to File]
Pipe Example
Count lines in command output:
cat largefile.txt | wc -l
Redirect Example
Save word count to a file:
wc -l filename.txt > linecount.txt
LabEx Recommendation
Practice these commands in LabEx's interactive Linux environments to master word count operations efficiently.