Linux find top n largest folders/files

If you wish to find the largest folders/files in a specific directory, you can use the following commands.

1. Find largest folders

For example to find the largest 20 directories in the /var/log directory, use this:

sudo du -hx /var/log | sort -hr | head -20

2. Find largest files

Alternatively, if you wish to find the largest 20 individual files in the /var/log directory, you can use this:

sudo find /var/log -type f -exec du -Sh {} + | sort -rh | head -n 20
Published
Categorized as UNIX Shell

By Leendert de Borst

Freelance software architect with 10+ years of experience. Expert in translating complex technical problems into creative & simple solutions.

Leave a comment

Your email address will not be published. Required fields are marked *