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 are the commands for Linux system to view log files

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you what the Linux system to view log file commands are, the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor to take you to study and learn the "Linux system view log file commands what are" this article.

Log location:

/ var/log/message system information and error log after startup is one of the most commonly used logs in Red Hat Linux

/ var/log/secure security-related log information

/ var/log/maillog Mail-related log information

/ var/log/cron log information related to scheduled tasks

/ var/log/spooler log information related to UUCP and news devices

Log messages related to / var/log/boot.log daemon start and stop

Tail

Parameters:

Tail [- f] [- c Number |-n Number |-m Number |-b Number |-k Number] [File] Parameter explanation:

-f this parameter is used to monitor the growth of File files.

-c Number reads the specified file from the Number byte location

-n Number reads the specified file from the Number line location.

-m Number reads the specified file from the Number multi-byte character location, for example, your file assumes that it includes Chinese characters, and if you specify the-c parameter, it may cause truncation, but using-m will avoid the problem.

-b Number reads the specified file from the 512-byte block location represented by Number.

-k Number reads the specified file from the 1KB block location represented by Number.

File specifies the target file name of the operation

In all the above commands, number is involved. If it is not specified, 10 lines are displayed by default. Number can be preceded by a plus or minus sign, indicating whether the offset is calculated from the top or from the tail.

Tail runnable files are generally below / usr/bin/.

Example: 1, tail-f filename description: monitor the tail content of the filename file (default 10 lines, equivalent to adding the parameter-n 10), refresh and display on the screen. Exit and press CTRL+C. 2. Tail-n 20 filename description: displays the last 20 lines of filename. 3. Tail-r-n 10 filename description: display the last 10 lines of filename in reverse order. 123456789head

Head only shows the first 10 lines of head-n 10 test.log query log file; head-n-10 test.log query log file shows all logs except the last 10 lines; 12345grep

Grep [options] main parameter: [options] main parameter:-c: only the count of matching rows is output. -I: case-insensitive (for single characters only). -h: the file name is not displayed when querying multiple files. -l: when querying multiple files, only the file names that contain matching characters are output. -n: displays matching lines and line numbers. -s: does not display error messages that do not exist or have no matching text. -v: displays all lines that do not contain matching text. The main parameter of pattern regular expression:: ignore the original meaning of special characters in regular expression. ^: matches the start line of the regular expression. $: matches the end line of the regular expression. To the end of the line that matches the regular expression []: single character, such as [A], that is, A meets the requirements. [-]: range, such as [Amurz], that is, A, B, C all the way up to Z meet the requirements. . All single characters -: there are characters and the length can be 0. 1234567891011121314151617181920sed

Use the sed command sed-n'5J 10p 'filename so that you can view only lines 5 through 10 of the file. 12cat

Cat has three main functions: 1. Displays the entire file at once. $cat filename 2. Create a file from the keyboard. $cat > filename can only create new files, not edit existing files. 3. Merge several files into one file: $cat file1 file2 > file parameter:-n or-- number starts from 1 to number all output lines-b or-- number-nonblank and-n is similar, but does not number-s or-- squeeze-blank for blank lines when you encounter more than two consecutive blank lines Replace it with a blank line of-v or-- show-nonprinting example: add the line number to the textfile1 file and enter cat-n textfile1 > textfile2 in the textfile2 file to append the content to the textfile3 after adding the line number to the textfile1 and textfile2 file contents (blank lines are not added). Cat-b textfile1 textfile2 > > textfile3 throws the test.txt file into the dustbin with a blank value of test.txt cat / dev/null > / etc/test.txt Note: > means to create, > > is to append. Don't get mixed up. 123456789101112131415161718192021tac (shown in reverse)

Tac reverses cat, so its function is the opposite of cat. Cat is displayed continuously on the screen from the first line to the last line, while tac is displayed on the screen from the last line to the first line! 12 mixed command

A. tail web.2016-06-06.log-n 300-f check the bottom, that is, the latest 300 log records And refresh B. grep 'nick' in real time | tail web.2016-04-04.log-C 10 to view 10 log records before and after the character' nick' C C. cat-n test.log | tail-n + 92 | head-n 20 tail-n + 92 indicates that the log after 92 lines is queried. Head-n 20 means to check what the first 20 records are in the previous query results. Linux is a free-to-use and free-spread UNIX-like operating system. Is a POSIX-based multi-user, multi-tasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.

The above is about "what are the commands for Linux system to view log files". If this article is helpful to you and you think it is well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more attention to 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

Development

Wechat

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

12
Report