wc command in linux with | flags | Examples
![]() |
wc command in linux |
You can use "wc" command with a file and it's going to show you the number of lines, number of words and number of characters in the file.
wc command
For example, I have a file "demo.txt" file. I am going to give "wc demo.txt" and press ENTER
![]() |
wc command |
$wc fileName
The first output here is "1" and this is the number of line in this file. "5" indicates No.of words in the file and then the third is the No.of characters here so the total number of character in this file is "21".
Using flags with wc Command
You can use certain flags in "wc" command which will give you specifically what you want.
[-c] flag
![]() |
wc command with -c flag |
$wc -c fileName
If you want to print only the No.of character then you can just use a flag called "-c" and this is going to print only the number of characters.
[-l] flag
![]() |
wc command with -l flag |
$wc -l fileName
If you want to count the number of lines you can just use the "-l" flag with "wc" command and then press ENTER it gives you No.of lines.
[-w] flag
![]() |
wc command with -w flag |
$wc -w fileName
[-L] flag
![]() |
wc command with -L flag |
$wc -L fileName
Conclusion
HAVE A NICE DAY💕