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

How does Linux view some lines of the log file through the command

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

Share

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

This article mainly shows you the "Linux how to view some lines of the log file through the command", 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 "Linux how to view some lines of the log file through the command" this article.

[1] start at line 3000 and display 1000 lines. That is, 3000cm 3999 lines are displayed

Cat filename | tail-n + 3000 | head-n 1000

[II] display 1000 to 3000 lines

Cat filename | head-n 3000 | tail-n + 1000

* Note the order of the two methods

Decompose:

Tail-n 1000: displays the last 1000 lines

Tail-n + 1000: displays from line 1000 and after line 1000

Head-n 1000: displays the first 1000 lines

[3] use sed command

Sed-n'5 filename 10p'so you can only look at lines 5 through 10 of the file.

Linux statistics of file lines

Syntax: wc [options] file...

Description: this command counts the number of bytes, words and lines in a given file. If no file name is given, it is read from standard input. Wc also gives presidential counts for all specified files. A word is the largest string distinguished by a space character.

The options for this command mean the following:

C counts the number of bytes.

-l count the number of rows.

-w count the word count.

These options can be combined.

The order and number of output columns are not affected by the order and number of options.

Always appear in the following order and each item has at most one column.

Number of lines, words, bytes, file name

If there is no file name on the command line, the file name does not appear in the output.

For example:

$wc-lcw file1 file2

4 33 file1

7 52 file2

11 11 85 total

Example analysis:

1. Count the number of js files in the demo directory:

Find demo/-name "* .js" | wc-l

two。 Count the number of lines of code for all js files in the demo directory:

Find demo/-name "* .js" | xargs cat | wc-l or wc-l `find. /-name "* .js" `| tail-N1

3. Count the number of lines of code in all js files in the demo directory and filter the blank lines:

Find / demo-name "* .js" | xargs cat | grep-v ^ $| wc-l

The above is all the contents of the article "how to view some lines of the log file through Linux command". 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