คู่มือนี้แนะนำคำสั่งตรวจสอบพื้นที่ดิสก์ใน Linux: df (Disk Free), du (Disk Usage), find (หาไฟล์ใหญ่)
1. df - Disk Free (พื้นที่ Partition)
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 57G 2.4G 52G 5% /
/dev/sda1 99M 12M 83M 12% /boot
/dev/sda2 15G 1.3G 13G 10% /home
-h= Human readable (K, M, G)-T= แสดง Filesystem Type-i= แสดง Inode Usage (สำคัญสำหรับไฟล์จำนวนมาก)
2. du - Disk Usage (ขนาดไฟล์/โฟลเดอร์)
# du -sh /path/to/dir
104K /path/to/dir
# รายละเอียดไฟล์/โฟลเดอร์ย่อย + Total
du -shc /path/to/dir/*
4.0K /path/to/dir/file1
64K /path/to/dir/subdir
100K total
-s= Summarize (แสดงแค่ Total)-h= Human readable-c= Grand Total--max-depth=1= แสดงระดับ 1 (เหมือน *)
3. find - หาไฟล์ขนาดใหญ่
# หาไฟล์ > 100MB ใน /home
find /home -type f -size +100M -exec ls -lh {} \;
# หาไฟล์ > 1GB ทั้งระบบ (ยกเว้น /proc /sys)
find / -type f -size +1G -not -path "/proc/*" -not -path "/sys/*" -exec ls -lh {} \;
# หาไฟล์ใหญ่ 20 อันดับแรก
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -hr | head -20
เครื่องมือ GUI / ทันสมัยกว่า
| Tool | คำอธิบาย |
|---|---|
| ncdu | NCurses Disk Usage - TUI เรียกดูโฟลเดอร์ ใช้คีย์บอร์ด นำทางง่าย (apt install ncdu) |
| baobab | Disk Usage Analyzer (GNOME GUI) |
| duf | Modern df replacement - สวย รองรับ JSON |
| dust | Modern du replacement - รูปแบบ Tree สวย |
| btrfs/ext4 quota | Quota ต่อ User/Project |