SEARCH

How-To Geek

Get the Top 10 Files or Directories on Ubuntu Linux

Ubuntu Linux has a rich set of commands for manipulating and accessing files. The du utility gives information on disk usage, and the sort utility can sort the results. Finally, we can run those results through the head command, which gives you the top 10 lines outputted through any other command. We’ll chain the commands together to get the output that we want.

First we’ll use the du -sm command to give the results in MB:

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

Now we can see that the results aren’t sorted, so we’ll sort them by the sort -nr command, which sorts by numerical value in reverse. Finally, we’ll run the results through head -10 to get the top 10 results:

This is the command we are going to run:

du -sm * | sort -nr | head -10

Here’s 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

Useful stuff.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 11/26/06

Comments (6)

  1. morganusvitus

    The site looks great ! Thanks for all your help ( past, present and future !)

  2. alex

    hi nice site.

  3. anatol

    Nise site!

  4. Vlad Ghinea

    This one of the most useful linux commands especially if you have a limited web host and your wordpress takes more than 500M with out attachements and you don’t know why. Hint :D

  5. jav

    Hi
    i need a script for clearing old files from any particular location
    the script must do fuser and it should pic only files which are not in use by any other process and than the script muxl do file to to those files which are not in use by any process and check any filers which is already compressed
    here it should pic the files which are not compressed till now

    the problem which i faced is i did fuser but when i am redirecting output its redirecting all files those which are in use and which are not in use
    and this script must ask the location which location we need to run this script to control mount point
    either like

    sh script.sh
    or using any controlfile for this script where i can add location

    its an urgent need please help me

    thanks in advance

  6. Gagarin

    Hi,

    you also could try:
    du -sh | sort -hr | head -10
    With this command, the results are shown in human readable way, or with units like G or M.

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!