How to Handle Full Disk Space in Linux?

How to Handle Full Disk Space in Linux?How to Handle Full Disk Space in Linux?Click the blue text to follow us

When the disk space is full, it can lead to application anomalies. How should we troubleshoot the issue of full disk space?

First, we need to confirm the disk space usage. To check the disk space usage, we can use the df command.

[root@VM-181-124 ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/vg_vm127178-lv_root                       50G   36G   11G  77% /
tmpfs                 3.9G  136K  3.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
/dev/mapper/vg_vm127178-lv_home                       42G  1.2G   38G   4% /home

The df -h command outputs the usage information for all disks. In the example above, the disk mounted at the root directory has reached a usage rate of 77%.

After checking the disk usage, we generally need to further examine the directories and files that are consuming a lot of disk space. A simple method is to continuously use the du command.

[root@VM-181-124 ~]# du -sh / | sort -h
...2.7G    /opt
3.8G    /var
13G     /root
13G     /usr
[root@VM-181-124 ~]# du -sh /usr/* | sort -h
...1.1G    /usr/share
1.2G    /usr/logs
8.6G    /usr/local

Using this method, we can clearly see where the disk space is being used, which directories are large, and what large files are in those directories.If we are only concerned about large files, there is actually a simpler way, which is to use the find command. For example, we can use the find command to locate files larger than 200M.

[root@VM-181-124 ~]# find / -type f -size +200M -exec ls -lh {} \;
...-rw-r--r--. 1 root root 1.2G 4月  19 2016 /usr/logs/message_push_center/.debug.2016-04-19.log
-rw-------. 1 root root 258M 12月  4 2015 /usr/local/experiment/heap_empty.bin
-rw-------. 1 root root 433M 12月  4 2015 /usr/local/experiment/heap.bin
-rw-r--r--. 1 nginx root 709M 4月  29 17:48 /data/logs/netty/jinsuibao/jinsuibao.access.log

Sometimes, after locating large files, we find that they are actually a bunch of log files.

-rw-r--r-- 1 root root 451M  4月 24 00:51 llm-xx-assistant-debug-2025-04-24_1.log.gz
-rw-r--r-- 1 root root 475M  4月 24 13:38 llm-xx-assistant-debug-2025-04-24_2.log.gz
-rw-r--r-- 1 root root 140M  4月 25 00:00 llm-xx-assistant-debug-2025-04-24_3.log.gz
-rw-r--r-- 1 root root 445M  4月 25 10:48 llm-xx-assistant-debug-2025-04-25_1.log.gz
-rw-r--r-- 1 root root 284M  4月 26 00:00 llm-xx-assistant-debug-2025-04-25_2.log.gz
-rw-r--r-- 1 root root 416M  4月 26 19:54 llm-xx-assistant-debug-2025-04-26_1.log.gz
-rw-r--r-- 1 root root  58M  4月 27 00:00 llm-xx-assistant-debug-2025-04-26_2.log.gz
-rw-r--r-- 1 root root 402M  4月 27 08:50 llm-xx-assistant-debug-2025-04-27_1.log.gz
-rw-r--r-- 1 root root 208M  4月 28 00:00 llm-xx-assistant-debug-2025-04-27_2.log.gz
-rw-r--r-- 1 root root 348M  4月 28 08:01 llm-xx-assistant-debug-2025-04-28_1.log.gz
-rw-r--r-- 1 root root 361M  4月 29 00:00 llm-xx-assistant-debug-2025-04-28_2.log.gz
-rw-r--r-- 1 root root 321M  4月 29 06:33 llm-xx-assistant-debug-2025-04-29_1.log.gz
-rw-r--r-- 1 root root 111M  4月 29 20:14 llm-xx-assistant-debug.log

At this point, to free up disk space, we can directly delete the log files. If there are many log files to delete, is there a good method? We can use the find + rm command. For example, I want to delete all log files older than 3 days.

find . -type f -mtime +3 -exec rm {} \;

To summarize the steps for locating the issue:1. Use df -h to check disk space usage.2. Use du -sh to check the disk space usage of each directory.3. Use the find command to directly locate large files.4. Use find + rm to clean up files that meet the criteria.

Previous RecommendationsHow to Handle Full Disk Space in Linux?Programming Tips: How to Design Good Function Parameters?How to Handle Full Disk Space in Linux?Stepped on a pit in sorting…How to Handle Full Disk Space in Linux?Sharing a fund trading arbitrage, with potential earnings of nearly 100%.ENDHow to Handle Full Disk Space in Linux?Don’t forget tolike, share, and show your support

Leave a Comment