Syntax
Description
Thewc (word count) command counts lines, words, and bytes in text input. It’s a fundamental tool for analyzing file sizes, counting records, and understanding text structure.
By default, wc displays all three counts. You can specify flags to show only specific counts.
Nash’s wc operates entirely in-memory and supports reading from files or standard input.
Options
Count lines only. Output the number of newline characters.
Count words only. Words are whitespace-separated tokens.
Count bytes only. Output the total number of bytes (characters).
When no options are specified,
wc displays lines, words, and bytes (in that order).
When multiple options are specified, counts appear in the order: lines, words, bytes.Examples
Default output (all counts)
lines words bytes
- 2 lines
- 4 words (hello, world, foo, bar)
- 20 bytes
Count lines only
Count words only
Count bytes only
echo.
Multiple flags
Count file contents
Pipeline Examples
Count matches
Count unique values
Words in a document
File size approximation
Count after filtering
.txt files in directory.
Average line length
Practical Use Cases
Verify CSV row count
Check if file is empty
Count log entries by level
Estimate reading time
Monitor log growth
Count code lines
Data validation
Advanced Examples
Compare file sizes
Count fields in CSV
Average words per line
Multiple files
Conditional processing
Output Format
All counts are right-aligned in 8-character fields:%8d for each count.
Single count format
Multiple counts format
Understanding Counts
- Lines
- Words
- Bytes
Number of newline characters (Output:
\n).3Files without a trailing newline may count one fewer line than expected.
Common Patterns
Count pipeline results
Check file emptiness
Sum counts across files
Store count in variable
Percentage calculation
Tips
Newline counting:
wc -l counts newline characters. A file without a trailing newline may show one fewer line than you expect.Empty input
Word definition
Words are separated by any whitespace: spaces, tabs, newlines.Byte vs character
For ASCII text, bytes = characters. For Unicode, may differ (not applicable in Nash’s VFS).Combining with other commands
Always usewc at the end of pipelines:
Performance
Nash’s
wc loads entire input into memory for counting. This is efficient for typical text files in the VFS but consider the memory footprint for very large datasets.