How to use Linux wc command

WBOY
Release: 2023-05-17 12:31:06
forward
2037 people have browsed it

Linux wc command is used to count word count.

Using the wc command, we can calculate the number of Bytes, words, or columns of a file. If the file name is not specified, or the file name is given as "-", the wc command will read the file from the standard input device. Read data.

Syntax:

wc
Copy after login
Copy after login
Copy after login

Parameters:

-c or --bytes or --chars Only the number of Bytes is displayed.

-l or --lines displays the number of lines.

-w or --words displays only the number of words.

--help Online help.

--version Display version information.

Example:

By default, wc will calculate the number of lines, words, and bytes of the specified file. The command used is:

wc
Copy after login
Copy after login
Copy after login

First check the content of the testfile file, you can see:

$ cat testfile  
Linux networks are becoming more and more common, but scurity is often an overlooked  
issue. Unfortunately, in today’s environment all networks are potential hacker targets,  
fro0m tp-secret military research networks to small home LANs.  
Linux Network Securty focuses on securing Linux in a networked environment, where the  
security of the entire network needs to be considered rather than just isolated machines.  
It uses a mix of theory and practicl techniques to teach administrators how to install and  
use security applications, as well as how the applcations work and why they are necesary.
Copy after login

Use wc statistics, the results are as follows:

$ wc testfile           # testfile文件的统计信息  
3 92 598
Copy after login

Among them, the 3 numbers are respectively Indicates the number of lines, words, and bytes of the testfile file.

If you want to count the information of multiple files at the same time, such as testfile, testfile_1, and testfile_2 at the same time, you can use the following command:

wc
Copy after login
Copy after login
Copy after login

The output result is as follows:

$ wc testfile testfile_1 testfile_2  #统计三个文件的信息  
3 92 598 testfile                    #第一个文件行数为3、单词数92、字节数598  
9 18 78 testfile_1                   #第二个文件的行数为9、单词数18、字节数78  
3 6 32 testfile_2                    #第三个文件的行数为3、单词数6、字节数32  
15 116 708
Copy after login

The above is the detailed content of How to use Linux wc command. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template