The wc command is used unix to get the word command,number of lines , character count etc.
syntax :
> wc [options]
The following are the option of a wc command
Options | Description |
-c | print the byte count in input |
-m | print the character count in input |
-l | print the newline count in input |
-L | print the length of the longest line in input |
-w | print the word count in input |
For example consider the input file sample.txt
>cat sample.txt apple orange mango kiwi Cherry |
Now lets look at the output if you give a wc command on it.
1. wc command
> wc sample.txt 5 5 31 sample.txt |
The output is printed like number of lines, words, and bytes in the file.
2. wc command to find number of line in a file - this will count for number of \n characters in the file and give that as output.
> wc -l sample.txt 5 sample.txt |
3. To find the number of file present in a directory the following combination of command can be used.
Lets say the directory contain 2 files.
> ls sample2.txt sample.txt |
You need to list the files in a directory and give the wc command. The output will be 2 in this case.
> ls | wc -l 2 |
Comments
Post a Comment