Ubuntu/Linux: Get disk space with “disk usage” (du, 2023, SSH)

Marc Wag­ner

March 20, 2023

2 min read|

“du” stands for “Disk Usa­ge” and is a con­so­le com­mand that dis­plays the disk space used by files and direc­to­ries. When you run the com­mand in the con­so­le, it shows you the size of files and direc­to­ries in bytes. This is espe­ci­al­ly useful if you want to deter­mi­ne which files and direc­to­ries take up the most space on your sys­tem.

Syntax description for use in the shell #

A short syn­tax descrip­ti­on for using disk usa­ge (du) over the SSH.

du OPTIONEN DATEIEN

OPTIONS and FILES are optio­nal para­me­ters.

Examples of the console command “du #

Here you can find an over­view of fre­quent­ly used para­me­ters that are used tog­e­ther with disk usa­ge.

# 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 formLong formDescrip­ti­on
-a–allSpe­ci­fies the allo­ca­ti­on for files and direc­to­ries, inclu­ding hid­den ones.
-B 100000–block-size=100000Spe­ci­fies the block size to be used for cal­cu­la­ting the memo­ry requi­re­ments.
-b–bytesCor­re­sponds to –block-size=1
-c–totalDis­plays the total sto­rage space at the end of the list.
-h–human-rea­­da­­b­leSpe­ci­fies the out­put in a rea­da­ble for­mat.
-kCor­re­sponds to –block-size=1000
-l–count-linksCounts the sizes seve­ral times if they are mates.
-L–dere­fe­renceDis­sol­ve all sym­bo­lic links
-D–dere­­fe­­rence-argsResol­ves only sym­bo­lic links spe­ci­fied on the com­mand line.
-d–max-depth=1Out­put sum for a direc­to­ry if it is N or less levels below the com­mand line argu­ment.
-mCor­re­sponds to –block-size=1M
–siCor­re­sponds to ‑h only with powers of 1000 ins­tead of 1024
-s–sum­ma­ri­zeShow only one sum for each argu­ment
-t–treshold=NIgno­re ent­ries smal­ler than N (if posi­ti­ve) or igno­re ent­ries lar­ger than N (if nega­ti­ve)
-X–exclude-from=FILEExclude files that match any pat­tern in FILE.
88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar