In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This "linux system how to view the log command" article, the article example code is introduced in great detail, with a certain reference value, interested friends must refer to, for the "linux system how to view the log command", Xiaobian sorted out the following knowledge points, please follow the pace of the editor step by step slowly understand, then let us enter the topic.
The role of Linux Syslog files:
Log file 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 method for Linux system to view log commands:
When there is a problem with your system, the first thing to do is to check the log. The author of this article introduces the specific methods of viewing logs under Linux.
During your career as a Linux administrator, you should check the log files sooner or later. Because log files can help you troubleshoot problems, the first thing every experienced administrator should do after a problem is to check the log.
You will find many logs: system log, kernel log, package manager log, Xorg log, startup process log, Apache log, MySQL log … Almost any system you can think of has corresponding log files.
Most log files are located in a convenient location: / var/log. These are system and service logs that are highly dependent on when something goes wrong with your operating system or an important service. If there is a problem with a specific desktop application, the log files will be written to different locations (for example, Thunderbird writes crash reports to'~ /. Thunderbird/Crash Reports'). Where the desktop application writes the log depends on the developer and whether the application allows custom log configuration.
We will focus on Syslog, which is at the heart of Linux troubleshooting. And a key question here is, how do you view those log files?
Fortunately, you have many ways to view Syslog, all of which need to be executed from the command line.
/ var/log
This is a critical folder on the Linux system. Open the terminal window and execute the command cd / var/log. Now execute the command ls, and you will see the log located under that directory (see figure 1).
Figure 1: log files located under / var/log/ are listed
Now, take a look at one of the logs.
Use less to view logs
One of the most important logs contained in / var/log is syslog. This special log file records everything except validating related messages. Suppose you want to see the contents of this log file, you can quickly execute the command less / var/log/syslog. This command opens the syslog log file and displays the header of the file. You can then use the arrow keys to scroll down one line at a time, use the spacebar to scroll down one page at a time, or use the mouse wheel to easily scroll through the file.
There is a problem with this approach, that is, syslog will become quite large; in addition, considering that the information you are looking for is most likely at or near the bottom, you may not want to spend time scrolling into the tail line by line or page by page, because syslog is turned on in the less command, you can also press the [Shift] + [g] keys to enter the tail of the log file immediately. The tail will be marked (END). Then, you can use the arrow keys or scroll wheel to scroll up to find the specific information you want.
Of course, it's not very efficient.
Use dmesg to view logs
The dmesg command outputs the kernel ring buffer. By default, this command displays all information from the kernel ring buffer. From the terminal window, execute the command dmesg, and the contents of the entire kernel ring buffer are output and displayed (see figure 2).
Figure 2:USB external driver shows a problem that needs to be studied
Fortunately, there is a built-in control mechanism that allows you to output only certain program modules (facility, such as daemons).
Suppose you want to view the log entries of the user program module, execute the command dmesg-facility=user. If any information is recorded to the tool, it will output the result.
Unlike the less command, executing dmesg displays the full contents of the log and takes you to the end of the file. You can always use the scroll wheel to browse the buffer of the terminal window (if applicable). Instead, you will want to input the output of dmesg into the less command through a pipe command, like this:
Dmesg | less
The above command outputs the contents of dmesg, allowing you to scroll through the output, just as you would with the less command to view the standard log.
Use tail to view logs
The tail command is probably one of the most convenient tools for viewing log files. The function of tail is to output the tail of the file. So, if you execute the command tail / var/log/syslog, it will only output the last few lines of the syslog file.
But wait a minute, the fun is not limited to that. The tail command has an important technique, which requires the use of the-f option. If you execute the command tail-f / var/log/syslog,tail, you will continue to monitor the log file and write the output to the next line of the file. This means that you can watch what is written to syslog in the terminal window in real time (see figure 3).
Figure 3: using the tail command, follow / var/log/syslog
Using tail in this way is a great way to troubleshoot problems.
To exit the tail command while watching the file, simply press [Ctrl] + [x].
You can also instruct tail to focus on only a few lines. Suppose you only want to see the last five lines written to syslog; to do this, you can execute this command:
Tail-f-n 5 / var/log/syslog
The above command focuses on the input of syslog and outputs only the last five lines. Once a new line is written to syslog, it removes the earliest line from the header. This is a good way to make the process of focusing on log files easier. I strongly recommend that you do not use this method to view logs with less than four or five lines, because you will eventually find that the input has been truncated and you cannot get the full details of an item.
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.
The above is all the contents of the article "how to View the Log Command on the linux system". 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.
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.