Inspired by this answer, I came up with the following to find directories of 1 GB or greater:
du -ht 1G / 2>/dev/null | sort -nr
Breakdown
du -ht 1G / 2>/dev/null | sort -nr
du -h # print sizes in human readable format (e.g., 1K 234M 2G)
t 1G # exclude entries smaller than 1G
/ # system root directory
2>/dev/null # redirect stderr (error) output to /dev/null, effectively ignoring it
| sort # pipe the output into sort
-n # compare according to string numerical value
r # reverse the sort, effectively putting the largest files and directories first
Note that du
's -t 1G
argument can take other size parameters too (from man du
):
-t
exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative. The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). Binary prefixes can be used, too: KiB=K, MiB=M, and so on.
Bear in mind that sort
just sorts on the numerical value, not the unit size. You might want to use du
's -B
option too, to round up to the nearest G
, for example.
Another useful du
argument might be -a
to list files, not just directories.
I use the following binaries on my system:
$ du --version
du (GNU coreutils) 9.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Torbjorn Granlund, David MacKenzie, Paul Eggert,
and Jim Meyering.
$ sort --version
sort (GNU coreutils) 9.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.