Example 1
Count Lines, Words, and Bytes
$ wc file.txt
25 150 892 file.txt
Displays line count, word count, and byte count for a file. The output shows 25 lines, 150 words, and 892 bytes. The filename is displayed at the end.
Default Output: Lines, Words, Bytes, Filename
Example 2
Count Lines Only
$ wc -l file.txt
25 file.txt
Counts only the number of lines using the '-l' option. One of the most commonly used wc options.
Common Use: Count log entries or lines of code
Example 3
Count Words Only
$ wc -w file.txt
150 file.txt
Counts only the number of words using the '-w' option. A word is defined as a sequence of characters delimited by whitespace.
Word Definition: Whitespace-delimited sequences
Example 4
Count Characters
$ wc -m file.txt
892 file.txt
Counts the number of characters using the '-m' option. Handles multi-byte characters correctly in UTF-8 and other encodings.
Multi-byte: Use -m for character count, -c for byte count
Example 5
Count Bytes
$ wc -c file.txt
892 file.txt
Counts the number of bytes using the '-c' option. For ASCII text, this equals character count.
File Size: Byte count matches file size
Example 6
Count Multiple Files
$ wc file1.txt file2.txt file3.txt
25 150 892 file1.txt
30 180 1024 file2.txt
15 90 512 file3.txt
70 420 2428 total
Counts statistics for multiple files and provides a total. Perfect for analyzing multiple files or getting aggregate statistics.
Project Stats: Get total line count across multiple files
Example 7
Count from Standard Input
$ cat file.txt | wc -l
25
Reads from standard input when no filename is provided. Useful in pipelines where output from one command becomes input to wc.
Pipelines: Combine with other commands for text processing
Example 8
Count Matching Lines
$ grep "error" /var/log/syslog | wc -l
42
Combines grep with wc to count lines matching a pattern. One of the most common command combinations for log analysis.
Log Analysis: Count errors, warnings, or specific events
Example 9
Count Files in Directory
$ ls -1 | wc -l
37
Counts the number of files in a directory by piping ls output to wc. The '-1' flag makes ls output one file per line.
Quick Count: Fast way to check number of files
Example 10
Get Maximum Line Length
$ wc -L file.txt
78 file.txt
Displays the length of the longest line in the file using the '-L' option. Useful for checking if files meet line length requirements.
Code Standards: Many style guides limit line length to 80 characters