Ubuntu/Linux: Get disk space with “disk usage” (du, 2023, SSH)
Marc Wagner
March 20, 2023
“du” stands for “Disk Usage” and is a console command that displays the disk space used by files and directories. When you run the command in the console, it shows you the size of files and directories in bytes. This is especially useful if you want to determine which files and directories take up the most space on your system.
Syntax description for use in the shell #
A short syntax description for using disk usage (du) over the SSH.
du OPTIONEN DATEIEN
OPTIONS and FILES are optional parameters.
Examples of the console command “du #
Here you can find an overview of frequently used parameters that are used together with disk usage.
# Zeigt den belegten Speicherplatz des Dateisystems: du -hs # Zeige den belegten Speicherplatz im aktuellen Verzeichnis du -hs . # Zeige den Verbrauch von Speicherplatz durch einen bestimmten Dateityp: du -hs *.pdf # Sortiere die Ausgabe nach Größe du -h * | sort -hr # Zeige nur die Größe der Dateien und Verzeichnisse im aktuellen Verzeichnis an du -h * --max-depth=1 # Zeige den verbrauchten Speicherplatz, wenn alle ZIP Dateien ausgeschlossen werden du --exclude="*.zip*" -hs # Zeige die größe eines bestimmten Pfades an du -h /var/www --max-depth=1
Options / parameters #
Short form | Long form | Description |
-a | –all | Specifies the allocation for files and directories, including hidden ones. |
-B 100000 | –block-size=100000 | Specifies the block size to be used for calculating the memory requirements. |
-b | –bytes | Corresponds to –block-size=1 |
-c | –total | Displays the total storage space at the end of the list. |
-h | –human-readable | Specifies the output in a readable format. |
-k | Corresponds to –block-size=1000 | |
-l | –count-links | Counts the sizes several times if they are mates. |
-L | –dereference | Dissolve all symbolic links |
-D | –dereference-args | Resolves only symbolic links specified on the command line. |
-d | –max-depth=1 | Output sum for a directory if it is N or less levels below the command line argument. |
-m | Corresponds to –block-size=1M | |
–si | Corresponds to ‑h only with powers of 1000 instead of 1024 | |
-s | –summarize | Show only one sum for each argument |
-t | –treshold=N | Ignore entries smaller than N (if positive) or ignore entries larger than N (if negative) |
-X | –exclude-from=FILE | Exclude files that match any pattern in FILE. |
Artikel von:
Marc Wagner
Hi Marc here. I’m the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.