Last active
August 13, 2025 12:18
-
-
Save thebouv/8657674 to your computer and use it in GitHub Desktop.
ducks: linux command for the 10 largest files in current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. :) |
@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.
已收到您的邮件,我会尽快回复。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this is for the current directory, why not
du -cks
without further arguments? No parsingls
or shell globbing necessary.