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

An example of unix file cleaning

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In the unix environment, we often encounter a situation where the file directory where the log is stored is full and needs to be cleaned up. Generally speaking, log files have a certain timeliness, for example, log files that are more than one week can be cleaned (take application logs as an example, database ARCH logs are based on whether the backup is completed). In the windows environment, we can use the graphical interface, sort according to time, then use the mouse box to select files, and then press the delete key, how convenient. But in the unix character interface, we do not have a mouse, no box selection, can only use commands, here we describe how to use commands to achieve our requirements simply and quickly. First of all, let's assume an application scenario: when a file system usage alarm is received, the / U01 directory on the host dbaleading1 is full and needs to be cleaned. After receiving this case, first of all do theoretical decomposition, how to think. 1. First of all, the / U01 directory must have many subdirectories. You must first find out which subdirectories take up most of the space. If you want to clean up the space, you must clean up more space. two。 Once you find a directory that takes up a lot of space, you need to know what files are stored in that directory. 3. According to the file, after determining the cleaning policy (such as retaining the expired log file with the suffix .log for 7 days), filter out the data that needs to be cleaned according to the policy. Clean up the filtered files. After the theoretical analysis is clear, we follow the steps and implement it step by step, and the process is very simple. The important thing is that we must know what we are doing in our daily operation and maintenance, especially when doing operations in important systems. What kind of impact will it have? after all, we are the last line of defense of the system. 1. Under windows, we can click on the folder, right-click, and view the properties to know the size of the folder. Under the unix character interface, we use the sort sorting method. The commands are as follows: [root@dbaleading1 ~] # cd / U01 [root@dbaleading1 U01] # du-sk * | sort-n about the role of specific commands, syntax, etc., you can use the man tool to view it. For example, enter man du under unix and the du command manual will appear. two。 Assuming that the / u01/log directory takes up a lot of space, go to the / u01/log directory and use the ls-ltr command to view the specific file information in that directory. If there are still multiple folders, repeat the first step. In the current scenario, we assume that there are a large number of application log files in this directory, ending with .log. 3. It is found that a large number of application logs take up space. According to the policy, we need to delete the log files from 7 days ago. We use the find command to achieve this step, as follows: [root@dbaleading1 ~] # find. -mtime + 7 | xargs ls-lrt in this command, the main command is find. -mtime + 7, its meaning is to look for files that were created more than 7 days ago in the current directory. The pipe command | xargs ls-lrt is used to arrange these files in chronological order and then display them. 4. If the file in step 3 has been confirmed and can be deleted, then replace the ls command in the pipe command with the delete command, as follows: [root@dbaleading1 ~] # find. -mtime + 7 | xargs rm-fr5. After the clean-up is completed, we use the command df-m to review and confirm that the process is correct, and the process is complete.

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

Servers

Wechat

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

12
Report