Quickly solve Linux log problems - a collection of practical tools
In Linux system operation and maintenance, logging is a very important part. It can help us deeply understand the cause of the problem and repair it when there is a problem with the system. But for beginners, viewing and solving log-related issues can be very difficult and tedious. Today, we will introduce you to several practical tools that can help you quickly solve Linux log problems.
We all know that logs are very important to us. Once a bug occurs in an application or the server crashes, we must use log files for debugging or further analysis. Therefore, the log file cannot simply be deleted.
At this time, we thought, it would be great if we could split the log files, so that we could keep important logs and delete unnecessary logs. This method will be introduced in detail below.
We can split logs every day. If so, in order to avoid confusion, the logs we split should all have dates. Of course, we can get the date through the following statement:
current_date=`date -d "-1 day" "+%Y%m%d"`
date -d "-1 day" means to get the date of the previous day, which means that if we operate today, we will cut yesterday's log. %Y%m%d is the specific date format, that is, the year, month, and day format, such as: 20181005.
Next, let’s cut the log.
split -b 65535000 -d -a 4 myout.txt ./log/log_${current_date}_
Among them, 65535000 is 60M, that is, the log file is cut according to the size of 60M, and the size can be customized. -d -a 4 indicates that the file suffix is 4 digits. After we cut the files, we need to number them in order, such as 0000, 0001, 0002...the 4 represents the number of digits.
The following ./log/log${current_date} is the prefix of the log file after cutting, and the current date is included in it. So, the final output format is similar to: log_20181005_0001.
After the log file is cut, the log file can be deleted, otherwise the meaning of cutting the file will be lost. The deletion method can be used in the following ways:
cat /dev/null > nohup.out
Write the above commands in a script and run it every day to cut the log file into several parts for easy troubleshooting. The complete code is as follows:
#!/bin/bash current_date=`date -d "-1 day" "+%Y%m%d"` split -b 65535000 -d -a 4 /home/alvin/myout.txt /home/alvin/log/log_${current_date}_ cat /dev/null > nohup.out
The above is the detailed content of Quickly solve Linux log problems - a collection of practical tools. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

There are many ways to customize a development environment, but the global Git configuration file is one that is most likely to be used for custom settings such as usernames, emails, preferred text editors, and remote branches. Here are the key things you need to know about global Git configuration files.
