The wc
(word count) command in Bash is a utility that allows users to count the number of lines, words, and characters in a file or standard input. It is a simple yet powerful tool for analyzing text data.
The basic syntax of the wc
command is as follows:
wc [options] [arguments]
-l
: Count the number of lines.-w
: Count the number of words.-c
: Count the number of bytes (characters).-m
: Count the number of characters (useful for multibyte characters).-L
: Print the length of the longest line.wc -l filename.txt
wc -w filename.txt
wc -c filename.txt
wc filename.txt
wc -L filename.txt
echo -e "Hello\nWorld" | wc -l
wc -lw filename.txt
will give you both line and word counts.wc
in combination with other commands through pipes to analyze output. For instance, grep "pattern" filename.txt | wc -l
will count how many lines contain a specific pattern.wc
can also read from standard input, making it versatile for quick counts without needing to specify a file.