متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 227System · Linux

How to find big files and folders fast

The alert says "/ is 92 % full". You need to know in two minutes where the space went: one huge log, thousands of old backups, a container image cache, a core dump? This how-to walks down from the top with du, lists the biggest single files with find, checks the usual suspects (journal, Docker, package caches), and covers the case where deleted files still use space.

  • 5 الدروس
  • 12 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

227.1

The quick answer

du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -15
du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -15
find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null | sort -k5 -h | tail

227.2

Step by step

  1. Which file system? — df -h shows which mount point is full. Work only inside that one: -x (du) and -xdev (find) stay on one file system, so other disks and network mounts are skipped.
  2. Walk down (lines 1–2) — the biggest folder at each level, then go one level deeper into it. Usually 3–4 steps reach the culprit.
  3. Biggest single files (line 3) — logs, dumps, ISO images, forgotten backups.
  4. Interactive — ncdu -x / (install ncdu) lets you browse sizes with the arrow keys and delete with d.
  5. Usual suspects:
journalctl --disk-usage
docker system df
dnf clean all
find /var/log -name '*.gz' -mtime +30 -size +10M

Journal too big → journalctl --vacuum-size=500M; Docker → docker system prune (read what it removes first).

  1. **Space used but du finds nothing** — deleted files still open by a process: lsof +L1. Restart that process.
  2. Space hidden under a mount point — files written to /data while the disk was not mounted are hidden under it later. Check with a bind mount: mount --bind / /mnt && du -sh /mnt/data && umount /mnt.
  3. Inodes full — df -i: millions of tiny files (sessions, mail queue, cache) can fill a disk that still has free bytes. Find folders with many files: find / -xdev -type f | cut -d/ -f2-3 | sort | uniq -c | sort -n | tail.

227.3

Check that it worked

After cleaning, df -h / shows the expected free space; the folder you cleaned is smaller in du -sh; the alert clears. Then fix the cause (log rotation, retention, cleanup job) so it does not come back.

الأوامر في هذا الدرس

227.4

Common problems

ProblemCauseFix
du takes very longIt scans network mounts or other disks.Use -x / -xdev; start in the full mount point.
df and du differ a lotDeleted open files, or files hidden under a mount point.lsof +L1; bind-mount check.
Disk full but many GB free in df -hInodes used up.df -i; remove many small files; fix the app.
Space not freed after deleting a logThe writer still has the file open.Restart/reload it; truncate instead (: > file).
Deleted something importantCleaned in a hurry.Restore from backup; read before rm, prefer moving first.
Root reserve on ext45 % reserved for root.Normal; tune2fs -m 1 on pure data disks if needed.

227.5

Go further

1Why use du -x and find -xdev?

They stay on one file system, so other disks and network mounts do not slow the search or confuse the result.

2Why can df show a full disk while du finds little?

Deleted files may still be open by a process, or files may be hidden under a mount point.

كل الأوامر في هذا الفصل