Tuesday, January 21, 2014

Getting Top 10 Files/Directories On Ubuntu Linux

Ubuntu Linux comprises of a rich set of commands to manipulate and access files. The du utility provides information on disk usage, and the sort utility on sorting results. Ultimately, those results can be run using the head command that offers you the top 10 lines outputted via other command. You can chain the commands together for getting the output that you desire.

Linux, Ubuntu, Directories, Files, Commands, Output, Sorting, Files, Directories, Chain




As stated on howtogeek.co, firstly we’ll utilise the du -sm command to provide the results in MB:

$ du -sm *
1 wp-config-sample.php
1 wp-config.php
14 wp-content
1 wp-feed.php
—- trimmed —

Now the results can be seen aren’t sorted and we can sort them using the sort -nr command that sorts by numerical value in reverse. Finally, the results can be run through head -10 for getting the top 10 results:

This is the command that is going to run:

du -sm * | sort -nr | head -10
Below is an example of the output:
$ 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

No comments:

Post a Comment