Top 10 Files & Directories in Ubuntu Linux - Find Largest Files

Understanding Disk Usage in Ubuntu Linux
Ubuntu Linux provides a comprehensive suite of commands for file management and disk space analysis. Among these, the du utility is instrumental in determining disk usage. The sort utility allows for the organization of this data, and the head command extracts a specified number of lines from the output.
Combining Commands for Efficient Analysis
By chaining these commands together, we can efficiently identify the largest files and directories. Initially, the du -sm command is employed to display disk usage in megabytes (MB). This provides a human-readable format for assessing space consumption.
Consider the following example output from the du -sm command:
$ du -sm *
1 wp-config-sample.php
1 wp-config.php
14 wp-content
1 wp-feed.php
---- trimmed ---
Sorting and Filtering Results
The initial output from du is typically unsorted. To address this, the sort -nr command is utilized. This sorts the results numerically, in reverse order, placing the largest items at the top.
Subsequently, the head -10 command is applied to display only the top 10 largest files or directories. This focuses the analysis on the most significant space consumers.
The complete command sequence is as follows:
du -sm * | sort -nr | head -10
Example Output
Running the combined command produces output similar to this:
$ du -sm * | sort -nr | head -10
14 wp-content
2 wp-includes
1 xmlrpc.php
1 xml.php
1 x.php
1 wp-trackback.php
1 wp-settings.php
1 wp-rss2.php
1 wp-rss.php
1 wp-register.php
Practical Applications
This technique is particularly useful for identifying directories or files that are consuming excessive disk space, enabling administrators to optimize storage and maintain system performance.