![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Linux WC Command Examples to Count Number of Lines, Words, Characters
The wc command also known as word count command is a fundamental command any Linux user should be aware of. It is mostly used with the l switch to do a line count, but it can actually give count of multiple things with various arguments supplied to it. Below is a list of what are those possible arguments. The we will see examples on each of them.
Sr.No | Command | Usage |
---|---|---|
1 | wc -c | Display number of bytes |
2 | wc -m | Display number of characters |
3 | wc -w | Display number of words |
4 | wc -l | Display number of lines |
5 | wc -L | Display length of longest line |
Lets consider the below file for our examples.
ubuntu@ubuntu:~$ cat inspire.txt Mastering anything needs practice. It aslo needs patience. And it needs time and other resources.
-c Option
Display the number of bytes in the file.
ubuntu@ubuntu:~$ wc -c inspire.txt
Running the above code gives us the following result:
98 inspire.txt
-m Option
Display the number of characters in the file.
ubuntu@ubuntu:~$ wc -m inspire.txt
Running the above code gives us the following result −
98 inspire.txt
-w Option
Display the number of words in the file.
ubuntu@ubuntu:~$ wc -w inspire.txt
Running the above code gives us the following result −
15 inspire.txt
-l Option
Display the number of lines in the file.
ubuntu@ubuntu:~$ wc -l inspire.txt
Running the above code gives us the following result:
3 inspire.txt
-L Option
Display the length of longest line in the file.
ubuntu@ubuntu:~$ wc -L inspire.txt
Running the above code gives us the following result −
38 inspire.txt
Only wc
Display the number of lines, words, and characters one after the other.
ubuntu@ubuntu:~$ wc inspire.txt
Running the above code gives us the following result −
3 15 98 inspire.txt