Home System Tutorial LINUX Use command to view partial lines of log file in Linux

Use command to view partial lines of log file in Linux

Jan 01, 2024 pm 10:05 PM
log file

[1] Starting from line 3000, display 1000 lines. That is, rows 3000~3999

are displayed

cat filename | tail -n 3000 | head -n 1000

【二】Display lines 1000 to 3000

cat filename| head -n 3000 | tail -n 1000

*Note the order of the two methods

break down:

tail -n 1000: Display the last 1000 lines
tail -n 1000: Start displaying from line 1000, and display
after line 1000 Head -n 1000: Display the first 1000 lines

【三】Use sed command

sed -n '5,10p' filename This way you can only view lines 5 to 10 of the file.

Linux statistics file line number

Syntax: wc [options] file...

Description: This command counts the number of bytes, words, and lines in a given file. If no filename is given, then standard input is read. wc also gives a total count of all specified files. Words are the largest string of characters separated by space characters.

The meaning of each option of this command is as follows:

 -c counts the number of bytes.
- l counts the number of rows.
- w counts the number of words.

These options can be used in combination.

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

Always displayed in the following order and with a maximum of one column per item.
Number of lines, number of words, number of bytes, file name
If there is no filename on the command line, the filename 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. Statistics of the number of js files in the demo directory:
find demo/ -name "*.js" |wc -l
2. Count the code lines of 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 code lines of all js files in the demo directory, and filter out empty lines:
find /demo -name "*.js" |xargs cat|grep -v ^$|wc -l

The above is the detailed content of Use command to view partial lines of log file in Linux. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Python script to monitor network connections and save to log file Python script to monitor network connections and save to log file Sep 01, 2023 am 10:41 AM

Monitoring network connections is critical to ensuring the stability and security of your computer system. Whether you are a network administrator or an individual user, having a way to track network connections and log related information can be invaluable. In this blog post, we will explore how to create a Python script to monitor network connections and save the data to a log file. By leveraging the power of Python and its rich libraries, we can develop a script to periodically check network status, capture relevant details such as IP address, timestamp, and connection status, and store them in a log file for future use refer to. This script not only provides real-time insights into network connections, but also provides historical records that aid in troubleshooting and analysis. Set up the environment before starting to write P

Where are the win10 log files? Where are the win10 log files? Jan 05, 2024 am 08:15 AM

The win10 log can help users understand the system usage in detail, and can help users record usage and problems. Many new users may not know how to open it. Let’s take a look at its detailed tutorial below. Where are the win10 log files: 1. Open "Control Panel" in settings 2. Click "Administrative Tools" 3. Find "Event Viewer" 4. Double-click "Windows Log" to open

Linux server log is too large, how to solve it? Linux server log is too large, how to solve it? Jun 29, 2023 pm 11:09 PM

Common problems of too-large log files on Linux servers and their solutions. With the rapid development of the Internet and the widespread use of servers, it has become a common problem that server log files are getting larger and larger. A large amount of log data not only takes up disk space, but may also affect the performance and operational stability of the server. This article will discuss the common problem of too large log files on Linux servers and provide some solutions. 1. Common log files on Linux servers. Common log files include system logs, application logs, We

Windows log files are located in C:\Windows\system32\logfiles Windows log files are located in C:\Windows\system32\logfiles Dec 22, 2023 pm 05:43 PM

Many users have encountered the situation of c: Windows\system32\logfiles on the win10 system. Nothing happens when pressing anything. Today, let’s take a look at how to solve this problem. win10 log file c: Windows\system32\logfiles: 1. Open the run, enter regedit to open, find HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders, find "desktop" on the right, right-click to modify, and change the

Common log file permission errors on Linux servers and how to fix them Common log file permission errors on Linux servers and how to fix them Jun 29, 2023 am 09:02 AM

Title: Common log file permission errors on Linux servers and how to fix them When running a Linux server, log files are very important. Successfully managing and protecting your server's log files is key to ensuring server security and stability. However, due to misconfiguration, attacks, or unexpected circumstances, log file permission errors may occur, resulting in limited access to the log file or the inability to write to the log. This article discusses some common log file permission errors and provides corresponding fixes to help administrators resolve the issue.

Learn more about the types and functions of Linux log files Learn more about the types and functions of Linux log files Feb 26, 2024 pm 10:33 PM

Detailed explanation of Linux log file types and functions In Linux systems, log files are a very important tool for administrators and developers. They record the operating status, behavior and events of the system. By analyzing log files, we can understand the operation of the system, discover problems in time and troubleshoot them. This article will introduce in detail the common log file types and their functions in Linux systems, and provide specific code examples to illustrate. 1. System log (/var/log/messages) The system log is L

Is it possible to delete Win10 log files? Is it possible to delete Win10 log files? Dec 26, 2023 pm 06:37 PM

The logs of win10 can help users understand the system usage in detail, and can help users record usage and problems. Most users will worry about whether its log files can be deleted. Let’s take a look at its details below. Can win10 log files be deleted? 1. The logs folder is the system log folder. This folder is used to record information about hardware, software and system problems in the system. It also monitors events that occur in the system, such as when our computer just If there is a problem with the computer crashing or automatically restarting, we can use it to check the cause of the error, or if the computer is attacked, we can also find traces of the attack from this folder. So the folder can be deleted. 2. We have performed any operations in the Win10 system,

Shell is an efficient command for analyzing log files, super easy to use! Shell is an efficient command for analyzing log files, super easy to use! Aug 01, 2023 pm 04:47 PM

My own small website runs on Alibaba Cloud's ECS. I occasionally analyze my website server logs to see the number of visits to the website. See if there are any hackers causing damage! So I collected and sorted out some server log analysis commands. You can try them!

See all articles