Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

du

Show how much disk space files and folders use.

Niveau
Dagelijks Linux
Groep
Schijven en bestandssystemen
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

du (disk usage) adds up the space that files use, folder by folder. Where df tells you that a file system is full, du tells you which folder fills it.

By default it shows every sub-folder. Usually you want -s (one total per argument), -h (readable sizes) and --max-depth=1 (one level).

Zo schrijf je het

du [OPTION]... [FILE]...

Opties 27

Meest gebruikt

-h, --human-readable
Sizes like 4.0K, 23M, 1.2G.
-s, --summarize
Only one total for each argument.
-d, --max-depth=n
Show totals only N levels deep.
-c, --total
Add a grand total at the end.
-a, --all
Show files too, not only folders.
-x, --one-file-system
Skip folders on other file systems.
--exclude=pattern
Leave out files that match.
-X, --exclude-from=file
Read exclude patterns from a file.
-t, --threshold=size
Show only entries bigger than SIZE (or smaller if negative).
--apparent-size
Show the file length, not the space on disk.
-b, --bytes
Apparent size in bytes.
-k, -m
Sizes in KiB / MiB.
-B, --block-size=size
Sizes in this unit.
--si
Like -h, with powers of 1000.
--inodes
Count inodes (number of files) instead of space.
-S, --separate-dirs
Do not include sub-folders in a folder's total.
-L, --dereference
Follow all symbolic links.
-D, -H, --dereference-args
Follow links given on the command line only.
-P, --no-dereference
Do not follow links (the default).
--time
Show the last change time of each folder.
--time=word
Which time: atime, access, use, ctime, status.
--time-style=style
Time format: full-iso, long-iso, iso, +FORMAT.
-0, --null
End each line with NUL.
--files0-from=file
Read the names from a file (NUL separated).
--help
Show help.
--version
Show the version.

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Size of one folder

    du -sh /var/log
    2.1G	/var/log

    One line, readable size.

  2. 2Which sub-folder is big?

    du -h --max-depth=1 /var | sort -h

    Sorted, the biggest at the bottom. Then go one level deeper.

  3. 3The 10 biggest folders on the root file system

    du -xh / 2>/dev/null | sort -h | tail -10

    -x stays on / and does not count other mounts.

  4. 4Sizes of all home folders

    du -sh /home/*

    Who uses the most space?

  5. 5Show files too, bigger than 100 MiB

    du -ah /srv | awk '$1 ~ /G|[0-9]{3}M/' | sort -h

    Lists big files and folders. find -size +100M is another way.

  6. 6Leave out some files

    du -sh --exclude='*.iso' ~/Downloads

    Size without the ISO images.

  7. 7Count files instead of size

    du --inodes -d 1 /var | sort -n | tail

    Finds folders with millions of small files (when df -i is at 100%).

  8. 8Grand total of several folders

    du -shc /var/log /var/cache /tmp

    The last line is the total.

  9. 9Real size vs. apparent size of a VM disk

    du -h vm.qcow2; du -h --apparent-size vm.qcow2

    A sparse file can look big but use little space.

  10. 10Show when folders changed

    du -h --time -d 1 /srv/backups

    Find backup folders that stopped growing.

  11. 11Only show folders above 1 GiB

    du -h -t 1G -d 2 /var/lib

    Hides all the small stuff.

  12. 12Check container storage

    du -sh /var/lib/containers/storage

    Container images often fill /var. podman system prune cleans unused images.

Let op

  • du counts only files it can read. Run it as root for system folders.
  • du does not see deleted files that are still open; df does. That explains differences.
  • On big trees du can take time and a lot of disk reads.

Tips om te onthouden

  • du -sh * = sizes here. du -h -d1 | sort -h = biggest last.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man du