WriteBash - This article will introduce
wc command. The
wc command is used to count the number of lines, words and bytes in the file.
Wc command syntax
There are 2 ways to use the
wc command as below.
wc to count the number of lines in a file, not the data in the pipeline.
$ wc [options] filename
wc in the pipeline, processing the output data from another command.
$ command-1 | command-2 | wc [options]
Use wc command to count number lines
Okey, now we will do an example. The first example is to use the non-pipeline command.
We have a text file with the following content. Now we will count the lines, count the words, count the number of bytes of that text file.
$ wc demo-wc.txt
For the second example, we will reuse the example included in the article about sort command. We will list the content in
/usr/bin and sort it. Now we will count the number files in both folders after sorting.
# ls /bin /usr/bin | sort | wc -l 2748
-cto print the byte counts.
-lto print the newline counts.
- And use
-wto print the word counts.
The wc command is often used in conjunction with the sort and uniq command. This set of 3 commands creates very powerful data filtering pipelines. You should combine it.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.