WC Unix Command
WC: Word Count (wc) command counts and displays the number of lines, words, character and number of bytes enclosed in a file.
Syntax: wc [options] [filename]
This command counts lines, words, and characters depending on the options used. Moreover, It takes one or more filenames as its arguments and displays four-columnar output. For example, let’s read our os1 file. And Also, we use wc command with that filename.
- print the newline counts.
- print the word counts.
- print the byte counts.
- print the character counts.
- print the length of the longest line.
- Red Hat
- Scientific Linux
- Linux Mint
- Pearl Linux
The ‘wc‘ command without passing any parameter will display a basic result of ”myfile.txt‘ file. Moreover, The three numbers shown below are 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the file.
12 16 112 myfile.txt
- Moreover, To count the number of newlines in a file using the option ‘-l‘, which prints the number of lines from a given file. Say, the following command will display the count of newlines in a file. Also, In the output, the first filed assigned as count and second field is the name of the file. $wc -l myfile.txt 12 myfile.txt
- Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a file. So, Type the following command to count the words in a file.
$wc -w myfile.txt
- When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of bytes and characters respectively in a file.
$wc -c myfile.txt
- The ‘wc‘command allow an argument ‘-L‘, it can be used to print out the length of longest (number of characters) line in a file. So, we have the longest character line (‘Scientific Linux‘) in a file.
$wc -L myfile.txt