Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of the wc command in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what is the use of the wc command in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of wc command in linux" this article.

Linux wc command

The wc command prints new lines, words, and bytes for each input file. The following is the syntax of the command line tool:

Wc [OPTION]... [FILE]...

The following is an explanation of wc's man documentation:

Print new lines, words, and bytes for each file, and if you specify more than one file, also list the total number of lines. A word is a sequence of non-zero-length characters separated by spaces. If no file is specified, or if the file is `-`, the standard input is read.

The following example of the wc style will give you a better understanding of the basic usage of the Qrooma command.

Note: in all the examples we will use a file named file.txt as the input file. The following is what the file contains:

Hihellohow are youthanks.Q1. How to print bytes

Print the number of bytes using the-c command option.

Wc-c file.txt

Here is the output produced by this command on our system:

How to print bytes

The file contains 29 bytes.

Q2. How to print characters

To print the number of characters, use the-m command line option.

Wc-m file.txt

Here is the output produced by this command on our system:

How to print characters

The file contains 29 characters.

Q3. How to print the number of newlines

Use the-l command option to print the number of new lines in the file:

Wc-l file.txt

Here is the output of our example:

How to print the number of newlines

Q4. How to print words

To print the number of words in the file, use the-w command option.

Wc-w file.txt

In our example, the output of the command is as follows:

How to print words

This shows there are six words in the file.

Q5. How to print the display width or length of the longest line

If you want to print the length of the longest line in the input file, use the-l command line option.

Wc-L file.txt

Here is the result of the command in our case:

How to print the display width or length of the longest line

So the longest line in the file is 11.

Q6. How to read the input file name from a file

If you have multiple file names and you want wc to read them from one file, use the-files0-from option.

Wc-files0-from=names.txt

How to read the input file name from a file

As you can see from the wc command, in this example, the line, word, and character count of the file file.txt is output. The file named file.txt is mentioned in the name.txt file. It's worth mentioning that to use this option successfully, the file name in the file should be terminated with NUL-- you can generate this character by typing Ctrl + v and then pressing Ctrl + Shift + @.

The above is all the content of the article "what is the use of wc commands in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report