In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this article "how to view the log file of linux", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to view the log file of linux" article.
In linux, log file refers to "log file", which records important events, including user's login information, system startup and security information, service information and so on. View the log file method: 1, use the "tail-n line number of log file name" command; 2, use the "head-n line number of log file name" command, and so on.
The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
In linux, log file refers to "log file". It is an important system information file, which records many important system events, including user login information, system startup information, system security information, mail-related information, various service-related information and so on. Some of this information is very sensitive, so only root users can read these log files in Linux.
The log file is stored in the / var/log/ directory, which is the location where the system log files are saved; in addition, the system service installed in the RPM package will also record the log in the / var/log/ directory by default (the service log installed by the source package is stored in the directory specified by the source package).
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 / var/log/boot.log daemon start and stop related log messages / var/log/wtmp this log file permanently records each user login, Events of logout and system startup and shutdown
How to check the log under linux?
There are many commands for Linux to view logs: tail, cat, tac, head, echo, and so on. Here are several common 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 display lines-Q,-- quiet,-- silent never outputs the first part of the given file name-s,-- sleep-interval=S is used with-f to indicate sleep for S seconds at intervals of each iteration
The usage is as follows:
Tail-n 10 test.log query the last 10 lines 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 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 queries the first 10 lines of logs in the log file; head-n-10 test.log queries all logs in the log file 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.logshift + G command to the end of the file and enter? Plus the keywords you want to search for, for example? 1213 Press n to look up keywords shift+n reverse lookup keywords less is similar to more, 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 file ps-ef | less ps view process information and display history via less paging | less view command history and use less paging display less log2013.log log2014.log to browse 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 file ps-ef | less ps view process information and display history via less paging | less view command history usage record and display less log2013.log log2014.log browsing multiple files via less paging commonly used command parameters:-b sets the size of the buffer-g only marks the last search keyword-I ignore the case of the search-m shows the percentage similar to the more command -N displays the line number of each line-o saves the less output in the specified file-Q does not use the warning tone-s to display a continuous empty behavior line / string: the ability to search down for "string"? String: the ability to search up for "string" n: repeat the previous search (and / or? About) N: reverse repeat the previous search (and / or? About) b turn back one page h to show the help interface Q exit less command
Generally, I check the log and apply other commands.
History / / all history records history | grep XXX / / records containing certain instructions in history history | more / / paged view records history-c / / clear all history records! Repeat the execution of the previous command to query the record and select:! 323 is about "how to view the log file of linux" this article, I believe we all have a certain understanding, I hope the content shared by the editor will be helpful to you, if you want to know more related knowledge content, please pay 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.
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.