Tips&Tricks

How to get top 10 largest files

bash

As we already saw, we can easily get to 10 largest directories (see “How to get top 10 largest directories in the current directory“). But there we used du utility – it shows directory size (or “estimate file space usage”). What utility shows file size? Oh… It’s just the ls!

Looks easy? But we need recursively mode, which doesn’t exist in ls. So we’ll use the the find! Also we need to sort it by size (5th column in ls -l output). And finally we’ll get first 10 lines of sorted list with command head.

TL;DR You can get top 10 largest files using following command:

find . -type f -print \
| xargs ls -l \
| sort -r -n -k 5,5 \
| head -10