wc command in Linux and Unix-like operating systems is used to count words, lines, and characters in files or input received from standard input. It provides basic statistics about the given input or files.
The basic syntax of the
wc command is as follows:
wc [options] [file(s)]
[options] represents the various flags and parameters you can use with the command, and
[file(s)] refers to the file or files you want to count.
Some commonly used options with
-l: Counts the number of lines.
-w: Counts the number of words.
-c: Counts the number of characters.
-m: Counts the number of characters, considering multibyte characters.
-L: Displays the length of the longest line.
-s: Prints only the total count, suppressing individual file counts.
To use the
wc command, open a terminal and enter the command followed by the desired options and the file(s) you want to count. Here are a few examples:
- Count the number of lines, words, and characters in a file:
- Count the number of lines in multiple files:
wc -l file1 file2 file3
- Count the number of words in a file and display the longest line:
wc -w -L filename
- Count the number of characters, considering multibyte characters, in a file:
wc -m filename
- Count the total number of lines, words, and characters from multiple files:
wc -lwc file1 file2 file3
These are just a few examples, and there are many more options and variations you can use with the
wc command. To explore additional options and information, you can refer to the
wc command’s manual page by typing
man wc in the terminal.