Total Pageviews

Sunday, 20 June 2021

清理vps的空间

 VPS 没装新东西,为什么硬盘越用越少了?”,这多半是因为系统上的各种日志长期积累下来的结果,比如 nginx, apache 等留下来的访问日志信息长时间不清理、而且访问量大的话会很容易就膨胀到 GB;有时候某种应用程序的日志藏在文件系统的深处,不易发觉;有时候自己拷贝了一些大文件放在某个地方时间长了就忘了。那么如何在 Linux 系统上找到这些占用硬盘空间的文件呢?

首先我们可以统计一下根目录下各个目录占用硬盘的情况,找出最占用硬盘的那个目录:

# du -sh /* 14M /bin 208M /boot 4.0K /cdrom 4.5M /dev 15M /etc 120G /home 0 /initrd.img 0 /initrd.img.old 1002M /lib 3.9M /lib32 4.0K /lib64 16K /lost+found 8.0K /media 4.0K /mnt 9.6G /opt du: cannot access ‘/proc/30918/task/30918/fd/4’: No such file or directory du: cannot access ‘/proc/30918/task/30918/fdinfo/4’: No such file or directory du: cannot access ‘/proc/30918/fd/3’: No such file or directory du: cannot access ‘/proc/30918/fdinfo/3’: No such file or directory 0 /proc 108K /root du: cannot access ‘/run/user/1000/gvfs’: Permission denied 9.9M /run 13M /sbin 4.0K /snap 4.0K /srv 0 /sys 2.2M /tmp 6.1G /usr 937M /var 0 /vmlinuz 0 /vmlinuz.old

从上面可看出 /home 占用了最多的硬盘,我们去看看 /home 下哪些用户占用了最多的空间:

# du -sh /home/* 120G /home/ivo 16K /home/lost+found

可以看到 vpsee 这个用户和他的 home 目录 /home/vpsee 用掉了最多的硬盘(105GB),我们再看看 /home/vpsee 下究竟哪些文件占用了空间,用下面的一行命令找出某个目录下(这里是 /home/vpsee)大小超过 500MB 的文件(打印前40行并按照 MB 从小到大排列):

# find /home/ivo -printf “%k %p\n” | sort -g -k 1,1 | \awk ‘{if($1 > 500000) print $1/1024 “MB” “ “ $2 }’ |tail -n 40 514.918MB /home/ivo/Downloads/sophos/sav-linux-free-9.tgz 561.742MB /home/ivo/backup/backup/goldendict_dictionary/En-En_OALD8/En-En_Oxford 565.656MB /home/ivo/backup/backup/goldendict_dictionary/En-En_Longman_Pronunciation3/En-En-Longman_Pronunciation.dsl.dz.files.zip 569.902MB /home/ivo/backup/backup/goldendict_dictionary/En-En_Merriam_Webster11/En-En-MWCollegiate11.dsl.dz.files.zip 601.047MB /home/ivo/221/xp/zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_vl_x14-74070.iso 601.047MB /home/ivo/221/xp/zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_x14-80404.iso 606.824MB /home/ivo/221/xp/XP纯净安装受控版.iso 633.691MB /home/ivo/.cache/.fr-owEFzg/H61-WI7-32位STM驱动.rar 639.91MB /home/ivo/blender/1.flv 665.453MB /home/ivo/221/backup/DCIM/Camera/VID_20171103_160714.mp4 697.953MB /home/ivo/blender/3.flv 1330.81MB /home/ivo/backup/backup/goldendict_dictionary/En-En_Longman_DOCE5/En-En-Longman_DOCE5.dsl.files.zip 1683.55MB /home/ivo/221/工控机测试工具/PCMARK/pcmark8/pcmark8-v2-3-293/cab1.cab 1753.82MB /home/ivo/.local/share/Steam/steamapps/common/Burst 1770.68MB /home/ivo/221/backup/DCIM/.thumbnails/.thumbdata3–1967290299 1977.25MB /home/ivo/221/工控机测试工具/PCMARK/pcmark8/pcmark8-v2-3-293/cab2.cab 1984.83MB /home/ivo/221/xp 2030.91MB /home/ivo/221/backup/DCIM/.thumbnails/.thumbdata3-1763508120 2691.54MB /home/ivo/221/工控机测试工具/PCMark10-v1-0-1275.zip 2968.88MB /home/ivo/221/工控机测试工具/PCMARK/pcmark8.zip 4310.44MB /home/ivo/221/g41_win7.GHO 27973MB /home/ivo/VirtualBox 28100.1MB /home/ivo/VirtualBox

可以看到 /home/ivo下面有这么多没用的东西,删除之。

No comments:

Post a Comment