linux磁碟已滿,檢視哪個檔案佔用多

Lafite-1820發表於2024-08-31

使用 df -h 檢視磁碟空間佔用情況

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           799M  3.1M  796M   1% /run
/dev/vda1        99G   99G   0G  100% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           799M     0  799M   0% /run/user/0

使用du -s /* | sort -nr命令檢視那個目錄佔用空間大

9999500 /root
2711464 /usr
794104  /var
633800  /lib
263164  /home
96780   /boot
75988   /tmp
12728   /bin
7308    /sbin
4868    /etc
3132    /run
16      /lost+found
12      /media
4       /srv
4       /opt
4       /mnt
4       /lib64
0       /vmlinuz.old
0       /vmlinuz
0       /sys
0       /proc
0       /initrd.img.old
0       /initrd.img
0       /dev

然後那個目錄佔用多 再透過du -s /root/* | sort -nr 一層層排查,找到佔用檔案多的地方。我今天發現的問題是tomcat日誌檔案二年的都沒刪過。有40g,後來找到log目錄刪除掉了。

使用du -h --max-depth=1檢視當前目錄下資料夾大小情況

1.2M    ./work
203M    ./webapps
16K     ./temp
7.4M    ./lib
804K    ./bin
236K    ./conf
11M     ./logs
224M    .

如果透過以上方法沒有找到問題所在,那麼可以使用 lsof | grep deleted 命令,看看是否刪除掉的檔案仍然被程序佔用而沒有進行實際刪除。

systemd-j   198             root  txt       REG              253,1     326224    1185339 /lib/systemd/systemd-journald (deleted)
systemd-l   399             root  txt       REG              253,1     618520    1185354 /lib/systemd/systemd-logind (deleted)
agetty      781             root  txt       REG              253,1      44104     664044 /sbin/agetty (deleted)
agetty      786             root  txt       REG              253,1      44104     664044 /sbin/agetty (deleted)
mysqld    13409            mysql    4u      REG              253,1          0     918684 /tmp/ib0wMnKJ (deleted)
mysqld    13409            mysql    5u      REG              253,1        100     918685 /tmp/ibQoVqHN (deleted)
mysqld    13409            mysql    6u      REG              253,1          0     918686 /tmp/ib0IhuER (deleted)
mysqld    13409            mysql    7u      REG              253,1          0     918687 /tmp/ibYj6KAZ (deleted)
mysqld    13409            mysql   16u      REG              253,1          0     918688 /tmp/ibJb6HC3 (deleted)
mysqld    13409 12709      mysql    4u      REG              253,1          0     918684 /tmp/ib0wMnKJ (deleted)
mysqld    13409 12709      mysql    5u      REG              253,1        100     918685 /tmp/ibQoVqHN (deleted)
mysqld    13409 12709      mysql    6u      REG              253,1          0     918686 /tmp/ib0IhuER (deleted)
mysqld    13409 12709      mysql    7u      REG              253,1          0     918687 /tmp/ibYj6KAZ (deleted)
mysqld    13409 12709      mysql   16u      REG              253,1          0     918688 /tmp/ibJb6HC3 (deleted)
mysqld    13409 13410      mysql    4u      REG              253,1          0     918684 /tmp/ib0wMnKJ (deleted)
mysqld    13409 13410      mysql    5u      REG              253,1        100     918685 /tmp/ibQoVqHN (deleted)
mysqld    13409 13410      mysql    6u      REG              253,1          0     918686 /tmp/ib0IhuER (deleted)
mysqld    13409 13410      mysql    7u      REG              253,1          0     918687 /tmp/ibYj6KAZ (deleted)
mysqld    13409 13410      mysql   16u      REG              253,1          0     918688 /tmp/ibJb6HC3 (deleted)
mysqld    13409 13411      mysql    4u      REG              253,1          0     918684 /tmp/ib0wMnKJ (deleted)
mysqld    13409 13411      mysql    5u      REG              253,1        100     918685 /tmp/ibQoVqHN (deleted)
mysqld    13409 13411      mysql    6u      REG              253,1          0     918686 /tmp/ib0IhuER (deleted)
mysqld    13409 13411      mysql    7u      REG              253,1          0     918687 /tmp/ibYj6KAZ (deleted)
mysqld    13409 13411      mysql   16u      REG              253,1          0     918688 /tmp/ibJb6HC3 (deleted)
mysqld    13409 13412      mysql    4u      REG              253,1          0     918684 /tmp/ib0wMnKJ (deleted)
mysqld    13409 13412      mysql    5u      REG              253,1        100     918685 /tmp/ibQoVqHN (deleted)
mysqld    13409 13412      mysql    6u      REG              253,1          0     918686 /tmp/ib0IhuER (deleted)

找到佔用檔案很大的程序,停止程序。之後重新啟動,就OK了。

相關文章