≡ Menu

How Do I Find The Largest Top 10 Files and Directories On a Linux / UNIX / BSD?

How do I find the largest top files and directories on a Linux or Unix like operating systems?

Sometime it is necessary to find out what file(s) or directories are eating up all your disk space. Further, it may be necessary to find out it at the particular location such as /tmp or /var or /home.

There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files:

  • du command : Estimate file space usage.
  • sort command : Sort lines of text files or given input data.
  • head command : Output the first part of files i.e. to display first 10 largest file.
  • find command : Search file.

Type the following command at the shell prompt to find out top 10 largest file/directories:
# du -a /var | sort -n -r | head -n 10
Sample outputs:

1008372 /var
313236  /var/www
253964  /var/log
192544  /var/lib
152628  /var/spool
152508  /var/spool/squid
136524  /var/spool/squid/00
95736   /var/log/mrtg.log
74688   /var/log/squid
62544   /var/cache

If you want more human readable output try:
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10


  • du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
  • du command -s option : show only a total for each argument (summary).
  • du command -x option : skip directories on different file systems.
  • sort command -r option : reverse the result of comparisons.
  • sort command -h option : compare human readable numbers. This is GNU sort specific option only.
  • head command -10 OR -n 10 option : show the first 10 lines.

The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):

for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11

Sample outputs:

179M	.
84M	./uploads
57M	./images
51M	./images/faq
49M	./images/faq/2013
48M	./uploads/cms
37M	./videos/faq/2013/12
37M	./videos/faq/2013
37M	./videos/faq
37M	./videos
36M	./uploads/faq

Find the largest file in a directory and its subdirectories using the find command

Type the following GNU/find command:

## Warning: only works with GNU find ##
find /path/to/dir/ -printf '%s %p\n'| sort -nr | head -10
find . -printf '%s %p\n'| sort -nr | head -10

Sample outputs:

5700875 ./images/faq/2013/11/iftop-outputs.gif
5459671 ./videos/faq/2013/12/glances/glances.webm
5091119 ./videos/faq/2013/12/glances/glances.ogv
4706278 ./images/faq/2013/09/cyberciti.biz.linux.wallpapers_r0x1.tar.gz
3911341 ./videos/faq/2013/12/vim-exit/vim-exit.ogv
3640181 ./videos/faq/2013/12/python-subprocess/python-subprocess.webm
3571712 ./images/faq/2013/12/glances-demo-large.gif
3222684 ./videos/faq/2013/12/vim-exit/vim-exit.mp4
3198164 ./videos/faq/2013/12/python-subprocess/python-subprocess.ogv
3056537 ./images/faq/2013/08/debian-as-parent-distribution.png.bak

You can skip directories and only display files, type:

find /path/to/search/ -type f -printf '%s %p\n'| sort -nr | head -10


find /path/to/search/ -type f -iname "*.mp4" -printf '%s %p\n'| sort -nr | head -10

Hunt down disk space hogs with ducks

Use the following bash shell alias:

alias ducks='du -cks * | sort -rn | head'

Run it as follows to get top 10 files/dirs eating your disk space:
$ ducks
Sample outputs:

Fig.01 Finding the largest files/directories on a Linux or Unix-like system

Fig.01 Finding the largest files/directories on a Linux or Unix-like system

{ 49 comments… add one }

  • Anonymous April 12, 2006, 11:13 am

    Great, but what if I only want the largest files and not the directories?

  • nixcraft April 12, 2006, 6:26 pm

    To find out largest file only use command ls as follows in current directory:
    ls -lSh . | head -5
    -rw-r–r– 1 vivek vivek 267M 2004-08-04 15:37 WindowsXP-KB835935-SP2-ENU.exe
    -rw-r–r– 1 vivek vivek 96M 2005-12-30 14:03 VMware-workstation-5.5.1-19175.tar.gz
    ls -lSh /bin | head -5
    You can also use find command but not du:
    find /var -type f -ls | sort -k 7 -r -n | head -10

    Hope this helps

  • nixcraft April 12, 2006, 6:35 pm

    And yes to find the smallest files use command:
    ls -lSr /var

    Or use find command with -size flag.
    find / -type f -size +20000k -exec ls -lh {} ; | awk ‘{ print $8 “: ” $5 }’

    Read man page of find for more info.

    • Spechal June 22, 2011, 5:47 pm

      “find / -type f -size +20000k -exec ls -lh {} ; | awk ‘{ print $8 “: ” $5 }’”

      needs to have the exec altered

      find / -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $8 “: ” $5 }’

      Also, I find this output easier to read

      find . -type f -size +20000k -exec ls -lh {} \; | awk ‘{print $5″: “$8}’

  • john January 19, 2007, 7:43 pm

    How do I can list all the files in several directories and at the end write the totat of all the files and directories.I’m using the du command as fallow:
    du -sh /public/base/sites/F*/*20070115*

    this command give me the size of all the files but not the global total.

    can somebody help me. please write me. john_fernandez@verizon.com.do

  • Joe January 23, 2007, 12:49 am

    “If you want more human readable output try:

    # du -ha /var | sort -n -r | head -n 10”

    Im pretty sure that this will put 999kb above 1gb so I don’t think that this works.

  • ChrisMM April 17, 2007, 7:26 am

    This does not work.

    # du -ha /var | sort -n -r | head -n 10″

    as Joe says this ignores files over 1gb

  • Dreyser May 27, 2007, 11:32 pm

    You could try this, gives a human readable output in MB

    find . -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head

  • Benjamin Schmidt September 26, 2007, 6:32 pm

    Human readable version:

    for X in $(du -s * | sort -nr | cut -f 2); do du -hs $X ; done

  • RudyD May 23, 2008, 4:06 pm

    If you set du to human readable I think it will not sort the way you really want.

    For the above problems. I would like to find a way to list only the last level directories’ sizes.

    (I want to filter somehow this:

    I just want to see the lasts of the tree!)



  • yanokwa June 11, 2008, 3:22 pm

    this is what i use.

    for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11

    • Srinivas October 25, 2013, 4:56 pm

      Worked like charm

  • rschu68 September 19, 2008, 1:46 pm

    find . -type f -print0| xargs -0 ls -s | sort -rn | awk ‘{size=$1/1024; printf(“%dMb %s\n”, size,$2);}’ | head

    ! -print0 for filenames with spaces …
    (and xargs -0 combined)

  • Winfan April 14, 2009, 12:04 am

    No wonder windows rule

    • Mr-Yellow July 26, 2011, 12:54 am

      Yeah you just go ahead and wait the 3 hours this search would take on Windows.

      • Nick November 30, 2011, 1:56 pm

        How about the 3 hours it takes to read through a bunch of unexplained programming nonsense. I swear half of the time all Linux guys do is insult other users….Example, the first listing is great as it begins to explain what the flags do, but I have no idea were to put some of them, pipes are not explained…ect

        • BigB June 24, 2015, 3:03 pm

          This is why Winblows users should not try and use Linux, they are very unintelligent and lack the ability to look up simple things.

    • Robert Sullivan September 28, 2015, 4:30 pm

      Fast forwarda few years, Linux won, bro :)

      “Late last week, hell had apparently frozen over with the news that Microsoft had developed a Linux distribution of its own. The work was done as part of the company’s Azure cloud platform, which uses Linux-based network switches as part of its software-defined networking infrastructure.” — SOURCE HERE.

  • beez June 19, 2009, 10:31 pm

    Winfan, I read this page wondering how to do these things in Windows — can you post instructions? Thanks!

    • Dave January 18, 2011, 5:56 pm

      This may vary depending on the version of Windows you’re using, but the basic procedure is: open the find/search window, go to the advanced options, and there will be an option there to enter in a size parameter. Simple.

      In XP, press F3 or go Start->Search. Choose “All files and folders”, then “More advanced options”, then “What size is it?”, then specify a size.

      • SamTzu August 6, 2013, 4:35 pm

        I believe beez was being sarcastic towards Winfan as was his right after Winfans brainless comment. Most Linux distro GUI’s come with search function just like Windows GUI.

        Now just try to do the search on command line on Windows (server)…


  • sridevika lover June 22, 2009, 6:38 pm

    thanks !!!!!!!!!!!!!!!!!

  • webmaster@@@@@@@@@@@ June 22, 2009, 6:39 pm

    great job !!!!!!!!!!!

  • notafan August 21, 2009, 9:54 pm

    @winfan… how do you do this in windows? you don’t :P

    • Jayman September 12, 2011, 8:31 pm

      c:\>dir /S /O-S | more

      The simple dir /S command from c:\ will give you all files and directories from c:\ all the way through the drive and will sort from largest to smallest running through each directory. You can filter using /A if you’d like to restrict by hidden, system, archive files, read only files etc. and passing the output to another windows command if you need to further restrict or search in the files for something like “show me all the files on my hard drive over 6MB that contain the word ‘log’ from largest to smallest.”

      /O will Specify the sort order for the files with the S after it sorting by file size (smallest first) putting the – in front of the S reverses the order.

      | more – you’re a unix dude, you should know what this means…

      But if someone is doing some cleanup through their harddrive, this is the simple command I’d start with.

      Just a note about the cockyness or us Unix admins (as I happen to be one now)
      Not everyone that uses windows started using it with a mouse kid!!! Also not everyone who prefers windows is not cross-platform… We were running 64 bit clustered NT boxes on RISC processors at Digital Equipment Corporation with failover and failback in 1996 brother. Don’t believe me? Find a really old copy of Windows NT ver 3.51 open it and you’ll see two folders NT and Alpha.

      The Department of Veterans Affairs had no problems with ever needing to reboot a “lousy unreliable windows box” because the Intel platform itself was the problem, not windows. We ran Alpha on 64 bit RISC processors and it was just as reliable as any Unix box or Mainframe we had. I had a Jensen Alpha running an exchange server for 5 years, and we only rebooted it every 6 months for giggles…

      Windows machines are made to be used by the masses which means more dumbasses can kinda run one. A good Admin is a good Admin, no matter what platform. Be nice and be helpful or don’t post.

  • Tihamer January 20, 2010, 6:08 pm

    Notafan wrote:
    @winfan… how do you do this in windows? you don’t :P

    Well, actually, there *is* cygwin (unix commands for Windows systems)

  • Keith White April 7, 2010, 10:44 am

    I find the following works rather well…

    du -xak . | sort -n | awk '{size=$1/1024; path=""; for (i=2; i 50) { printf("%dMb %s\n", size,path); } }'

    It lists all files or directories bigger than 50MB (just change size>50 to alter that) in the current directory (change the “.” to a directory path to specify another one) in a friendly, human-readable way and happily plays with spaces (I used it on an NTFS mount in fact).

    • Brian March 10, 2011, 3:00 am

      I get a syntax error when coptying and pasting this command

      • Thomas December 21, 2011, 11:19 am

        Same here…

  • Rafiq February 18, 2011, 8:51 pm

    I found this one the simplest one.
    ls -lSh . | head -5

  • Satish June 13, 2011, 10:22 pm

    I have learnt a lot from your posts

    thanks alot and keep it up.

  • aaa October 4, 2011, 2:44 pm

    ls -lR | sort -nr +4 -5 | head

  • Nalinda December 14, 2011, 11:29 pm

    Thanks heaps for this. It saved me lot of time.

  • Steve August 22, 2012, 1:14 pm

    The easiest way would be
    ls -lSh | head -n 10

  • tobeportable March 10, 2013, 12:06 pm

    install `ncdu`

  • Avi April 18, 2013, 2:50 pm

    I second that! Try NCDU, it’s command-line and gives you interactive folder listings.

  • remke April 18, 2013, 7:43 pm

    -> dispus2.7 (google)

    With kind regards,

  • Azad June 4, 2013, 11:56 am

    How to go at last line at a big file directly by using the unix command. cud u plz assist me for the same @ ibm_guy2000@yahoo.com

    • Azheruddin September 17, 2014, 4:56 am

      By using vi editor edit the file
      and press shift + g you will move to last line of the file.

      now to add or insert you need to press i i.e insert mode and add data then to save
      press wq!
      the file will be saved and you will quit from file .

  • karthik July 13, 2013, 12:35 am

    How can i find the largest file size in centos ..
    and also through dates and all the details of the file.


  • Anjana.S July 21, 2013, 7:55 am

    how can i open a human readable file from my current directory?

  • shirish October 13, 2013, 4:30 am

    hows this !!!
    ##top 20
    # find /var -ls 2>/dev/null | sort -nrk 7 | awk ‘{print $NF}’ | xargs ls -lSh | head -20

  • Christian Benesch November 8, 2013, 1:00 pm

    The following is working and sorting properly by Gigabyte, Megabytes and Kilobytes:

    for i in G M K; do du -ah | grep ^[0-9\.]*$i | sort -nr -k 1; done | head -n 110

    Basically it makes sure to grep from the *beginning* of the line and to include the possible decimal points. In your version it would have stumbled over filenames beginning with numbers and a ‘G’ for instance.

    • Dharmesh October 29, 2015, 3:31 pm

      thats it, neat!

  • Suraj November 15, 2013, 3:56 pm

    I need to display only the name of the file with maximum size in home directory…please help..

  • Silverback December 3, 2013, 8:06 pm
    find / -xdev -size +2048 -ls  

    List all files larger than 1 mb. Displays

    1632043 2656 -rw-r-----   1 root     adm       2715648 Dec  3 13:51 /var/log/mail.log

    Datasource: IBM AIX Version 3 Commands Reference Volume 1
    A bit dated but it works just fine on Debian 7.

  • Deepak March 13, 2014, 10:33 am

    How to find the largest top 10 files with the file modified date?

  • Mohammed Zafar January 5, 2015, 6:08 am

    I want to check which folder take a more size because i want clean it

    Filesystem Size Used Avail Use% Mounted on
    /dev/sda3 15G 12G 1.9G 87% /

  • Christopher Ranschaert October 29, 2015, 4:48 pm

    I have the following:

    alias dush='du -sch .[!.]* * | sort -h'

    This adds the .hidden .directories as well (skipping parent .. directory), and sorts in human-readable format (GNU version of sort)

Leave a Comment

   Tagged with: , , , , , , , , , , , , , , , , , , , , ,