在 Linux 中 du / find 的功能非常強大,尤其是搭配 sort / head 指令後,可以快速尋找出所需的目錄/檔案及佔用磁碟空間最大的目錄/檔案。
找出 /home 目錄中佔用磁碟空間最大的目錄
# du -hsx /home/* | sort -hr | head
15G /home/share
13G /home/s0990
12G /home/www
6.3G /home/t850008
6.2G /home/s0970
5.6G /home/s0980
4.4G /home/s0960
3.8G /home/s0100
3.8G /home/homework
1.5G /home/s0950
找出佔用磁碟空間最大的學生前三名
# du -hsx /home/s0990/* /home/s0980/* | sort -hr | head -n 3
340M /home/s0980/s0980055
281M /home/s0990/s0990145
281M /home/s0990/s0990136[@more@]找出前 10 大的檔案
# find /home -type f -printf ‘%s %pn’ | sort -nr | head
4670320640 /home/www/course_3-6.iso
2519356635 /home/share/PhotoCap/PCMaterial_V5_MultiFrame.exe
1785901819 /home/share/PhotoCap/PCMaterial_V6_MultiFrame.exe
1593472746 /home/53.tar.bz2
1552238558 /home/share/38/38.html.tar.bz2
1513110984 /home/www/all_g3_big5.zip
1513110912 /home/www/all_g3.zip
1507640047 /home/drbl.tar.bz2
1258466165 /home/share/PhotoCap/PCMaterial_V5_Frame.exe
1131084431 /home/share/PhotoCap/PCMaterial_V6_Frame.exe
找出前 10 大的 exe 檔案
# find /home -type f -iname ‘*.exe’ -printf ‘%s %pn’ | sort -hr | head
2519356635 /home/share/PhotoCap/PCMaterial_V5_MultiFrame.exe
1785901819 /home/share/PhotoCap/PCMaterial_V6_MultiFrame.exe
1258466165 /home/share/PhotoCap/PCMaterial_V5_Frame.exe
1131084431 /home/share/PhotoCap/PCMaterial_V6_Frame.exe
663175919 /home/share/PhotoCap/PCMaterial_V100.exe
459156905 /home/share/PhotoCap/PCMaterial_V4_Frame.exe
439657482 /home/share/PhotoCap/PCMaterial_V4_MultiFrame1.exe
431579494 /home/share/PhotoCap/PCMaterial_V300.exe
408804542 /home/share/PhotoCap/PCMaterial_V200.exe
401967094 /home/share/PhotoCap/PCMaterial_V4_MultiFrame2.exe