Linux users can run the following command to find the top 10 largest files and directories in the current file system.
1. Find Top 10 Largest Files and Directories (Current Directory)
To analyze disk usage within your current working directory, use:
du -ahx . | sort -rh | head -10
In the above command:
du -ahx .du: Estimates disk usage-a: Includes both files and directories-h: Human-readable format (KB, MB, GB)-x: Stays within the same filesystem
sort -rh- Sorts output by size in descending order
head -10- Displays the top 10 largest entries
This command is very useful in quickly identifing space-heavy files in a project or directory.
2. Find Top 10 Largest Files on the Entire System
To scan the whole system for the largest files:
sudo find / -type f -exec du -h {} + 2>/dev/null | sort -rh | head -n 10
In the above command:
sudo: Required to avoid permission errorsfind / -type f: Searches all regular files in the root filesystem-exec du -h {} +: Calculates size of each file2>/dev/null: Suppresses permission denied errorssort -rh | head -n 10: Shows top 10 largest files
3. Find Files Larger Than a Specific Size
To locate files exceeding a defined size (e.g., 100MB):
find / -type f -size +100M -exec ls -lh {} +
The command option “-size +100M” filters files larger than 100MB. Don’t forget to use k for KB, M for MB, G for GB.
4. Find Largest Directories in Linux
To find the biggest directories (e.g., in /home):
du -a /home | sort -n -r | head -n 10
The du command lists disk usage of all directories and files, sorts them from largest to smallest and displays top 10 results.
You must use du -h for human-readable output.
5. Find Largest Files Only
If you’re interested only in files (not directories):
find -type f -exec du -Sh {} + | sort -rh | head -n 10
In the above command:
-type f: Filters only filesdu -Sh: Displays size in human-readable format, summarizing each file- Sorted to show largest files first
The find Command
The find command is a powerful utility used to search for files and directories based on multiple criteria.
find command syntax:
find [path] [options] [expression]
Command options:
[path]: Starting point (e.g.,.,/,~)[options]: Controls behavior (e.g.,-maxdepth)[expression]: Search filters (e.g.,-name,-type,-size)
Usage Example:
find . -name "*.log"
Finds all .log files in the current directory.
The du Command
The du (disk usage) command estimates file and directory space usage.
du command syntax:
du [OPTIONS]... [FILE]...
Mots-used Command Options:
-h→ Human-readable output-s→ Summary (total size only)-a→ Include all files-c→ Show grand total-d N→ Limit directory depth
Usage Examples:
- Check current directory usage:
du -h - Summarize a folder:
du -sh /var/log - Limit depth:
du -h -d 1
I hope you find this post useful.
