Linux Terminal Command: wc
The wc command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what wc does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The wc command prints counts of newlines, words, and bytes for specified files.
Common Options & Syntax
wc [options] [arguments]
Here are the most common flags used with wc:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
wc -l log.txt
What it does: Prints the number of lines in ’log.txt'.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
wc -w -m -c document.txt
What it does: Displays the word count (-w), character count (-m), and byte count (-c) of ‘document.txt’.
⚙️ Warning & Common Pitfalls
[!WARNING] Character count and byte count can differ on files containing multi-byte Unicode characters. Use
-cfor raw storage sizes, and-mfor text lengths.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: