The wc command reads either standard input or a list of files and generates newline count, word count, and byte count.
wc <option> <filename>
Some useful command-line options supported by the
wc command are as following:
Execute the wc command without any argument, it will display the number of lines, words, and bytes from the file
wc <file name>
1 4 17 f1
To display the complete count information of multiple files give the below command
wc <file1> <file2>
The '-l' option is used to print the total number of lines in a file
wc - l <file name>
The '-m' option is used to print the total number of characters in the file.
wc -m <file name>
The '-c' option is used to display the total number of bytes in a file.
wc -c <file name>
The '-w' option is used to display the total number of words from a file. It is executed as follows:
wc -w <file name>
To count the total number of files in a directory give the below command,
The output of
wc --help command :
To count the number of occurrences of a particular word using grep and wc command in a text file give the below command
grep -o -i <search word> <file name> | wc -l
grep -o -i Hi! f1 | wc -l
-ooption used with the grep command gives an output when the given text is matched in the file and passes the output to the
wc-lcommand which counts the number of times the provided text is matched in the file.