How to Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find the unnecessary junks and free up them from your hard disk.

This brief tutorial describes how to find the largest files and folders in the Linux file system using du and find command. If you want to learn more about these two commands, then head over to the following articles.

  1. Learn 10 Useful ‘du’ (Disk Usage) Commands in Linux
  2. Master the ‘Find’ Command with this 35 Practical Examples

How to Find Biggest Files and Directories in Linux

Run the following command to find out top biggest directories under /home partition.

# du -a /home | sort -n -r | head -n 5
Find Largest Directories in Linux

Find Largest Directories in Linux

The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, run:

# du -a | sort -n -r | head -n 5
Find Biggest Directories Only

Find Biggest Directories Only

Let us break down the command and see what says each parameter.

  1. du command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head : Output the first part of files.
  7. -n : Print the first ‘n’ lines. (In our case, We displayed first 5 lines).

Some of you would like to display the above result in human readable format. i.e you might want to display the largest files in KB, MB, or GB.

# du -hs * | sort -rh | head -5
Find Top Directories Sizes in Linux

Find Top Directories Sizes in Linux

The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:

# du -Sh | sort -rh | head -5
Find Largest Folder and Sub directories

Find Largest Folder and Sub directories

Find out the meaning of each options using in above command:

  1. du command: Estimate file space usage.
  2. -h : Print sizes in human readable format (e.g., 10MB).
  3. -S : Do not include size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command:

# find -type f -exec du -Sh {} + | sort -rh | head -n 5
Find Top File Sizes in Linux

Find Top File Sizes in Linux

To find the largest files in a particular location, just include the path besides the find command:

# find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
OR
# find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5
Find Top File Size in Specific Location

Find Top File Size in Specific Location

The above command will display the largest file from /home/tecmint/Downloads directory.

That’s all for now. Finding biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share on your social networks and support TecMint.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Senthil Kumar

A Linux Consultant, living in India. He loves very much to write about Linux, Open Source, Computers and Internet. Apart from that, He'd like to review Internet tools and web services.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

20 Responses

  1. Bob Stein says:

    My problem isn’t big files, it’s a huge number of tiny files. How can I list the biggest directories *by the number of files*?

    • Ravi Saive says:

      @Bob,

      You can find the number of files including its sizes with the following command:

      # find . -xdev -type f | cut -d "/" -f 1,2 | sort | uniq -c | sort -n
      

      The above output lists the number of files contained in a directory, including subdirectories, sorted by number of files.

  2. Adam Wells says:

    How do I can list all the files in several directories and at the end write the total 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.

  3. Aaren Watts says:

    To find big files and directories you have to use 3 commands is 1 line du, sort, and head.

    1- du : Estimate file space usage
    2- sort : Sort lines of text files or given input data
    3- head : Output the first part of files i.e. to display first 10 largest file

    Let give on example:- .

    Find largets 20 files or directories, I prefer root access to execute the commands.

    # du -a /var | sort -n -r | head -n 20
    
    Output
    [[email protected] ~]# du -a /etc  | sort -n -r | head -20
    125520  /etc
    66376   /etc/gconf
    44932   /etc/gconf/gconf.xml.defaults
    43084   /etc/selinux
    43052   /etc/selinux/targeted
    40772   /etc/selinux/targeted/modules
    40740   /etc/selinux/targeted/modules/active
    21388   /etc/gconf/schemas
    18928   /etc/selinux/targeted/modules/active/base.linked
    14716   /etc/selinux/targeted/modules/active/base.pp
    4796    /etc/selinux/targeted/modules/active/modules
    2972    /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
    2768    /etc/rc.d
    1884    /etc/selinux/targeted/policy
    1876    /etc/selinux/targeted/policy/policy.21
    1876    /etc/selinux/targeted/modules/active/policy.kern
    1836    /etc/gconf/schemas/gnome-terminal.schemas
    1328    /etc/gconf/schemas/apps_nautilus_preferences.schemas
    1284    /etc/firmware
    1276    /etc/firmware/microcode.dat
    [[email protected] ~]#
    
  4. David Parker says:

    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

  5. Staffing Services says:

    I tried this:

    # find . -type d -size +100M
    

    Which shows result like this:

    ./u01/app/june01.dbf
    ./u01/app/temp01.dbf
    ./u01/app/smprd501.dbf
    ./home/abhishek/centos.iso
    ./home/abhishek/filegroup128.jar
    

    Now this is my issue. I only want the name of those files located in folders that are consuming space at / and not at /u01 or /home. Since / is base of everything, it is showing me every file of my server.

    Is is possible to get big files that is contributing to 78% of / ?

  6. Cloud Consulting Services says:

    “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}’

  7. This lists files recursively if they’re normal files, sorts by the 7th field (which is size in my find output; check yours), and shows just the first file.

    # find . -type f -ls | sort +7 | head -1
    

    The first option to find is the start path for the recursive search. A -type of f searches for normal files. Note that if you try to parse this as a filename, you may fail if the filename contains spaces, newlines or other special characters. The options to sort also vary by operating system. I’m using FreeBSD.

    A “better” but more complex and heavier solution would be to have find traverse the directories, but perhaps use stat to get the details about the file, then perhaps use awk to find the largest size. Note that the output of stat also depends on your operating system.

  8. Gilles Pion says:

    Sorting using “sort -n” the output of “du -Sh” (“h” stands for “human-readable”) gives incorrect results: sizes are printed by “du” in float values with trailing unit indicator (none, “K”, “G”). For instance 1.2M is sorted as *lower* than 4.0K (since 1 < 4) which is false.

    So, instead of
    find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
    You'd better use
    find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5
    which gives the 5 top size files.

    • Gilles Pion says:

      Oups! Didn’t noticed the “-h” option to “sort” too (which I didn’t knew BTW).
      So that’s OK.

    • Ravi Saive says:

      @Gilles,

      Thanks for the tip, will include your command as alternative way to achieve the same results with better format..

  9. Good advice. I’ve put together a tool that makes a lot of this even easier, in case anyone is interested.

    I expect that urls are not permitted in content, but are invited for one’s name, so I’ve placed the bitbucket link to my script, “duke” there.

    • Ravi Saive says:

      @Gregory,

      Thanks for sharing the duke tool, seems excellent with nice presentation of files sizes and their ages, will surely write about this duke tool on our next article. Could you please send more about the tool and features at [email protected]?

  10. mikeg9b says:

    You can also use ncdu.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.