🐧 Linux / Shell Scripting
Beginner
How does wc (word count) work?
Answer
wc (word count) counts lines, words, and bytes in a file or stdin. wc file outputs three numbers: line count, word count, and byte count. Use specific flags to get only one: wc -l file (lines only — very common for counting results), wc -w file (words only), wc -c file (bytes), wc -m file (characters, different from bytes for multi-byte encodings). Piping is common: ls | wc -l counts files in a directory, grep -c pattern file counts matching lines (more efficient than grep | wc -l). wc is a simple but frequently used tool in shell pipelines.
Previous
How do head and tail work for viewing file portions?
Next
How do sort and uniq work together?