Signup/Sign In
PUBLISHED ON: MARCH 26, 2023

Word Count Command in Linux Terminal with examples

The "wc" command is a common command in Linux and Unix-like operating systems that is used to display information about files or streams. The command stands for "word count" and is used to count the number of lines, words, and bytes in a file or input stream.

In this way, the "wc" command is a useful utility that can help Linux users manage and manipulate data efficiently.

Syntax of wc command:

wc [OPTION]... [FILE]...

1. Count nunber of words (wc -w): In Linux, the "wc -w" command is used to count the number of words in a file or input stream. The "wc" stands for "word count" and the "-w" option tells the command to count only the words.

wc -w names.txt city

2

2. Count number of characters (wc -c): In Linux, the "wc -c" command is used to count the number of bytes in a file or input stream. The "-c" option is used to specify that only the byte count should be displayed.

wc -c names.txt city

3

3. wc -m: In Linux, the "wc -m" command is used to count the number of characters in a file or input stream. The "-m" option is used to specify that only the character count should be displayed.

wc -m names.txt city

4

4. wc -L: In Linux, the "wc -L" command is used to find the length of the longest line in a file or input stream. The "-L" option is used to specify that only the length of the longest line should be displayed.

wc -L names.txt city

5

5. wc --version: In Linux, the "wc --version" command is used to display the version information for the "wc" command.

wc --version

6

6. wc: In Linux, the "wc" command is used to display information about files or input streams. The command stands for "word count" and is used to count the number of lines, words, and characters in a file or input stream.

wc city

7

By default, the "wc" command displays the number of lines, words, and bytes in a file. To use the "wc" command, open a terminal window and type "wc" followed by the name of the file you want to count.

wc names.txt city

8

Conclusion

The "wc" command is a useful utility in Linux that is used to display information about files or input streams. This command can be used to count the number of lines, words, and bytes in a file or input stream, and it is often used to analyze or manipulate text data when mixed with other commands.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.