-
-
Save thebouv/8657674 to your computer and use it in GitHub Desktop.
du -cks * | sort -rn | head -11 | |
# Usually set this up in my bash profile as an alias: | |
# alias ducks='du -cks * | sort -rn | head -11' | |
# Because it is fun to type ducks on the command line. :) |
This script has helped me so much.
alias ducks='du -cks $(ls -A) | sort -rn | head -n11'
will search in hidden directories also. Helpful for large caches.
@georgedorn you're right -- I use this now:
alias ducks='while read -r line;do du -sh "$line";done < <(ls -1A) | sort -rh | head -n11'
Thanks for the improvement
If this is for the current directory, why not du -cks
without further arguments? No parsing ls
or shell globbing necessary.
@mcguirepr89 this fails on folders with spaces in the name.
@thebouv I'd use du -cksx
if there are any symlinks or sshfs mounts into large networked filesystem, like a NAS...
Suddenly wondering why this has got attention when I posted it in 2014. Weird.
@georgedorn Yeah guess it’s just never come up. 🤷🏼♂️
I saw it linked on Mastodon.
I saw it linked on Mastodon.
Hah! Neat.
alias 🦆='ls -1A | xargs -d "\n" -I{} du -sb "{}" 2>/dev/null | sort -rn | head -n11 > /tmp/sizes.txt && awk "{sum+=\$1} END {print sum}" /tmp/sizes.txt | numfmt --to=iec --suffix=B > /tmp/total.txt && awk "{print \$1, \$2}" /tmp/sizes.txt | while read -r size name; do size_fmt=$(numfmt --to=iec --suffix=B <<< "$size"); echo -e "$size_fmt\t$name"; done && echo "Total: $(cat /tmp/total.txt)" && rm /tmp/sizes.txt /tmp/total.txt'
You can cut out the sort if you are willing to accept that you are only checking on files, not recursively into folders:
ls -AlS |head -11
I often want to know most recent files, so -t is useful.
It would be better to use this: