Skip to content

du

List all directory sizes and sort by size

du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh
du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc

Display a numbered list of 50 biggets files sorted by size (human readable)

du -ah | sort -hr | head -n50 | cat -n

Ultimate current directory usage command

du -a max-depth=1 \
    |sort -n \
    |cut -d/ -f2 \
    |sed '$d' \
    |while read i; do 
        if [[ -f $i ]]; then 
            du -h "$i"; 
        else 
            echo "$(du -h max-depth=0 "$i")/"; 
        fi; 
    done

easily find megabyte eating files or directories

du -cks * \
    |sort -rn \
    |while read size fname; do 
        for unit in k M G T P E Z Y; do 
            if [[ $size -lt 1024 ]]; then 
                echo -e "${size}${unit}\t${fname}"; 
                break; 
            fi; size=$((size/1024)); 
        done; 
    done

List sub dir, sort by size, the biggest at the end, with human presentation

du max-depth=1 -x -k \
    |sort -n \
    |awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } {gsub(/^[0-9]+/, human($1)); print}'

  • Comments are closed on this article!

Last update: December 6, 2022 16:13:32