How to clean up the disk space of a Linux server

Sometimes, the service suddenly hangs, but it can't be started again. At first glance, it turns out that the disk space is full, so how do you clean it up? The introduction is as follows:

df -h , this command is used to view the server space, the effect diagram after running is as follows:

As you can see, 8G is still available.

 

du -h --max-depth=1 , this command is used to view the current directory, which file occupies the most, the operation effect is as follows:

As you can see, the iov directory occupies a relatively large space, 20G.

In addition, du -sh * , this command is also used to view the size of each file and folder in the current directory, the operation effect is as follows:

It can be seen that the iov directory occupies a relatively large space, 12G.

Enter the iov directory, execute the above view command repeatedly, follow up all the way, and find files that take up a lot of space in each directory. Useless files can be deleted.

As you can see, this nohup.out log file occupies a lot (1.9G). Now leave it empty.

You can use the command: cp /dev/null nohup.out . After clearing it, check it again, and it really takes up less (696K).

 

So, if it is not the nohup.out file that takes up space, how to clean it up?

It's very simple, just use the normal delete command.

Delete command: rm [options] file or directory 

 

Option description:

-f -force Ignore non-existent files and force deletion without any prompt

-i --interactive delete interactively

-r | -R --recursive recursively delete all directories and files in the listed directories

-v --verbose show detailed steps

Command example:

1. Delete the a.txt file

rm -rf a.txt

2. Delete the mplogs directory

rm -rf mplogs

 

Here we use example 2 to delete, the effect is as follows:

 

After cleaning up some, go back to the root directory, and the occupation has become less.

 

Welcome to follow the WeChat public account (Java Practice Notes):

Focus on the accumulation of Java technology, share free Java technology dry goods, study notes, study materials, etc., and strive to make this a Java knowledge station.

Scan the code to pay attention, reply to "Java Interview" to get the interview questions and analysis of Dachang

Guess you like

Origin blog.csdn.net/u012660464/article/details/78923011