Skip to content

Instantly share code, notes, and snippets.

@thebouv
Last active June 12, 2025 23:44
Show Gist options
  • Save thebouv/8657674 to your computer and use it in GitHub Desktop.
Save thebouv/8657674 to your computer and use it in GitHub Desktop.
ducks: linux command for the 10 largest files in current directory
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. :)
@zchrissirhcz
Copy link

It would be better to use this:

du -sh * | sort -hr | head

@Sasino97
Copy link

This script has helped me so much.

@mcguirepr89
Copy link

mcguirepr89 commented Jan 25, 2022

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

@Goorzhel
Copy link

If this is for the current directory, why not du -cks without further arguments? No parsing ls or shell globbing necessary.

@georgedorn
Copy link

@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...

@thebouv
Copy link
Author

thebouv commented Jan 23, 2023

Suddenly wondering why this has got attention when I posted it in 2014. Weird.

@georgedorn Yeah guess it’s just never come up. 🤷🏼‍♂️

@Goorzhel
Copy link

I saw it linked on Mastodon.

@thebouv
Copy link
Author

thebouv commented Jan 23, 2023

I saw it linked on Mastodon.

Hah! Neat.

@jacrys
Copy link

jacrys commented Jun 12, 2025

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'

@zchrissirhcz
Copy link

zchrissirhcz commented Jun 12, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment