Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the wc command of linux to count the number of bytes, words, and lines of a file

Shulou Source: shulou.com Published: 2022-06-02 12:42:22 09月19日 Update

Editor to share with you the use of linux's wc command to count the number of bytes, words, lines of the file, I hope you will learn a lot after reading this article, let's discuss it together!

The wc command counts the number of bytes, words, and lines in the specified file, and displays the statistical results. Using the wc instruction, we can calculate the number of Byte, words, or columns of a file. If the file name is not specified, or if the file name is given as "-", the wc instruction will read data from the standard input device. Wc also gives the presidential count of the specified file.

Syntax format: wc [parameters] [file]

Commonly used parameters: coach

Reference example

Word count:

[root@linuxcool ~] # cat test.txt

Hello world

Hello world

Hello world

Hello world hello world

[root@linuxcool ~] # wc-w test.txt

10 test.txt

Count bytes:

[root@linuxcool ~] # wc-c test.txt

60 test.txt

Statistics of characters:

[root@linuxcool] # wc-m test.txt

60 test.txt

Count rows:

[root@linuxcool ~] # wc-l test.txt

4 test.txt

Print the length of the longest line:

[root@linuxcool] # wc-L test.txt

23 test.txt has finished reading this article. I believe you have a certain understanding of using linux's wc command to count the number of bytes, words and lines of the document. If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

Tags: Files statistics words bytes commands parameters instructions articles longest at the same time names characters finished examples commonly used presidents data more standard format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Shulou Information MySQL Xiaomi