In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what are the log viewing methods in Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
There are many commands for Linux to view logs: tail, cat, tac, head, echo, and so on. This article only introduces a few commonly used methods.
1 、 tail
This is one of the most common ways for me to check.
Command format: tail [necessary parameters] [Select parameters] [File]
-f loop read
-Q does not display processing information
-v displays detailed processing information
Number of bytes displayed by-c
-n shows the number of rows
-Q,-- quiet,-- silent never outputs the first part of the given file name
-s,-- sleep-interval=S is used with-f to indicate dormancy for S seconds at intervals of each iteration.
The usage is as follows:
Tail-n 10 test.log query the log of the last 10 lines at the end of the log
Tail-n + 10 test.log query all logs after 10 lines
Tail-fn 10 test.log loop to view the last 1000 rows of records in real time (the most commonly used)
It is also used in conjunction with grep, such as:
Tail-fn 1000 test.log | grep 'keyword'
If the amount of data queried at one time is too large, you can turn the page to view it, for example:
Tail-n 4700 aa.log | more-1000 can be displayed on multiple screens (ctrl + f or spacebar can be a shortcut key)
2 、 head
As opposed to tail, head looks at the number of previous lines of log.
Head-n 10 test.log query the first 10 lines of logs in the log file
Head-n-10 test.log query log file all logs except the last 10 lines
Other parameters of head refer to tail
3 、 cat
Cat is displayed continuously on the screen from the first line to the last line.
Display the entire file at once:
$cat filename
Create a file from the keyboard:
$cat > filename
Merge several files into one file:
$cat file1 file2 > file can only create new files, not edit existing files.
Append the contents of one log file to another:
$cat-n textfile1 > textfile2
Clear a log file:
$cat: > textfile2
Note: > means create, > > is append. Don't get mixed up.
Other parameters of cat refer to tail
4 、 more
The more command is a text filter based on the vi editor that displays the contents of a text file by page in a full-screen manner and supports keyword positioning in vi. There are several keyboard shortcuts built into the more list, such as H (get help information), Enter (scroll down one line), space (scroll down one screen), and Q (exit command). The more command reads the file back and forth, so the entire file is loaded at startup.
The command displays one screen of text at a time, stops after the screen is full, and displays a message at the bottom of the screen giving the percentage of the file that has been displayed so far:-More- (XX%)
Syntax for more: more file name
Enter goes down n lines and needs to be defined. The default is 1 line.
Ctrl f scrolls down one screen
The space bar scrolls down one screen
Ctrl b returns to the previous screen
= output the line number of the current line
: F output file name and line number of the current line
V call the vi editor
! Command invokes Shell and executes the command
Q exit more
5 、 sed
This command can find a specific section of the log file. It can be queried by line number and time range according to a range of time.
By line number
Sed-n'5 filename 10p'so you can only look at lines 5 through 10 of the file.
According to the time period
Sed-n'/ 2014-12-17 16-14-17 17-17 17-17 17-17-17 17-12-16-17 17-17-17 17-12-17 16-17-17 17-12-17 16-17-17-17-17-14-12-16-16-17-17-17-17-12-17-16-16-17-14-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-16-17 17-12-17 16-17 17-12-17
6 、 less
When the less command queries the log, the general process is as follows
Less log.log
Shift + G command to the end of the file and enter? Plus the keywords you want to search for, for example? 1213
Press n to find the keyword up
Shift+n reverse lookup keyword
Less is similar to more in that you can browse files at will with less, while more can only move forward, not backward, and less does not load the entire file before viewing it.
Less log2013.log View Files
Ps-ef | less ps to view process information and display it via less paging
History | less view command history and display it through less paging
Less log2013.log log2014.log browses multiple files
Common command parameters:
Less is similar to more in that you can browse files at will with less, while more can only move forward, not backward, and less does not load the entire file before viewing it.
Less log2013.log View Files
Ps-ef | less ps to view process information and display it via less paging
History | less view command history and display it through less paging
Less log2013.log log2014.log browses multiple files
Common command parameters:
-b sets the size of the buffer
-g marks only the last keyword searched
-I ignore the case of the search
-m displays the percentage similar to the more command
-N displays the line number of each line
-o Save the less output in the specified file
-Q does not use warning tones
-s displays a row of continuous empty behavior
/ string: the ability to search down for "string"
? Strings: the ability to search up for "strings"
N: repeat the previous search (and / or? Related)
N: reverse repeat the previous search (and / or? Related)
B turn back one page
H displays the help interface
Q exit less command
Generally, I check the log and apply other commands.
History / / all historical records
History | grep XXX / / Records that contain certain instructions in the history
History | more / / View records by page
History-c / / clear all history records
!! Repeat the previous command
After querying the record, select:! 323
Linux log file description
/ 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
/ var/log/wtmp this log file permanently records the events of each user logging in, logging out, and system startup and downtime
This is the end of this article on "what are the log viewing methods in Linux?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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: 251
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.