Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of cleaning disk by linux

Shulou Source: shulou.com Published: 2022-06-02 21:27:32 09月22日 Update

This article will explain in detail the methods of linux disk cleaning for you. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. View disk information

Df-lh

We can see that the 40G capacity under the mount point / dev/xvda1 under Filesystem has been exhausted. The next step is to delete files that take up a lot of disk space but are useless.

2. Locate the largest file directory

Cd / # goes to the root directory. Du-h-max-depth=1 # looks for the current directory and which folder takes up the most space

You can see that / usr this path takes up a lot of disk space and takes up 21G. Sharp-eyed students may see the last item showing 24g, which indicates that the total disk space occupied by all files in the current directory is 24g.

Do the same, after several judgments, locate the log file of tomcat.

Judging from the above figure, the 17G file is in the current directory (tomcat log directory) file.

3. Locate the largest file

Ls-lhS # presents files in order from largest to smallest

The final location file is: catalina.out this log file.

4. Confirm that the file is not occupied

Anyone can delete a file: rm-f catalina.out, but it's best to make sure you want to download it and let the developer analyze the log.

In Linux or Unix systems, deleting files through rm or file manager will unlink (unlink) from the directory structure of the file system. However, if the file is opened (there is a process in use), the process will still be able to read the file and disk space will always be occupied.

/ usr/sbin/lsof | grep deleted # confirm whether the deleted file is occupied

It is indeed occupied. According to the pid provided in the second column, enter the command: kill-9 13117 to kill the process.

Enter the command again: df-lh

As shown in the figure, disk space is freed. The problem was dealt with smoothly.

On the linux disk cleaning methods to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: File disk directory space log location maximum process method content command capacity article more knowledge article system input good sharp eye Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia MariaDB Apple Shulou Information