
- Operating System Tutorial
- OS - Home
- OS - Overview
- OS - Components
- OS - Types
- OS - Services
- OS - Properties
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling algorithms
- OS - Multi-threading
- OS - Memory Management
- OS - Virtual Memory
- OS - I/O Hardware
- OS - I/O Software
- OS - File System
- OS - Security
- OS - Linux
- OS - Exams Questions with Answers
- OS - Exams Questions with Answers
- Operating System Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
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
- Related Articles
- Guide to the Linux wc Command
- C program to count characters, lines and number of words in a file
- Apt Linux Command with Examples
- 25 Practical Examples of Linux Find Command
- md5sum Command in Linux with Examples
- 10 Netstat Command Examples on Linux
- AWK Command in Linux with Examples
- 5 Interesting Linux ‘sort’ Command Examples
- Apropos Linux Command Explained {With Examples}
- Frequently Used Examples of ‘Fuser’ Command in Linux
- 5 ‘hostname’ Command Examples for Linux Newbies
- 5 ‘stat’ Command Examples for Linux Newbies
- 10 7zip (File Archive) Command Examples in Linux
- 25 Useful ‘ps Command’ Examples for Linux Process Monitoring
- Count lines in a file using Linux bash
