How to find large file size on linux

Often time, you may need to know which file contains large file size, and delete it to save space. Here’s a code pattern to show you how to find large file size on Linux :

find {directory} -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

1. File size >= 100MB

Find all files that have a size >= 100MB, from root folder and its sub-directories.

sudo find / -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Result

/Applications/Diablo: 2.3G
/Applications/Diablo: 203M
/Applications/Diablo: 978M
/Applications/Diablo: 1.4G
/Applications/Diablo: 1.3G
/Applications/Diablo: 1.5G
/Applications/iPhoto.app/Contents/Resources/PointOfInterest.db: 242M

2. File size >= 50MB

Find all files that have a size >= 50MB, from folder ‘/Users/mkyong’ and its sub-directories.

find /User/mkyong -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Result

/Users/mkyong/Downloads/command_line_tools_for_xcode_june_2012.dmg: 147M
/Users/mkyong/Downloads/ubuntu-12.04-desktop-i386.iso: 701M
/Users/mkyong/Downloads/X15-65805.iso: 3.0G
/Users/mkyong/Library/Preferences/com.google.code.sequel-pro.plist: 104M
Note
Above command tested for Ubuntu and Mac OSX.

References

  1. Unix find command
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • http://www.thegeekscope.com The Geek Scope

    Here is a script to display the largest files on your system.

    http://www.thegeekscope.com/linux-script-to-find-largest-files/

    Following is the sample output of the script:

    # sh get_largest_files.sh / 5

    [SIZE (BYTES)] [% OF DISK] [OWNER] [LAST MODIFIED ON] [FILE]

    56421808 0% root 2012-08-02 14:58:51 /usr/lib/locale/locale-archive
    32464076 0% root 2008-09-18 18:06:28 /usr/lib/libgcj.so.7rh.0.0
    29147136 0% root 2012-08-02 15:17:40 /var/lib/rpm/Packages
    20278904 0% root 2008-12-09 13:57:01 /usr/lib/xulrunner-1.9/libxul.so
    16001944 0% root 2012-08-02 15:02:36 /etc/selinux/targeted/modules/active/base.linked

    Total disk size: 23792652288 Bytes
    Total size occupied by these files: 154313868 Bytes [ 0% of Total Disc Space ]

    *** Note: 0% represents less than 1% ***

  • http://www.newsasnow.com newsasnow.com

    When you use find with size option. I guess you are assuming that file size has to be more than +100000k which will is not the solution to the topic you are covering
    Topic is: “How to find large file size on linux (Solution)”

    So this will give only the file larger than size specified.
    find / -type f -size +100000k …

    The solution that might get the results.
    find . -type f -exec du {} \; | sort -rn | head -10

    so the command says:- find all files and run then run du (estimate file space usage) then sort as per the size and get me 10 largest. I might like to know largest file even if it few kb’s …

    The only problem I am working on is this will take long time to get me results. Any ideas on how to make this command faster ??

  • the dsc

    Ops, just now I noticed, the “sort” part won’t work quite right though. 1.000 GB files will appear at the top, followed by 100 MB files, going down until you reach 900MB file sizes. It still helps, as long as you have that in mind.

  • the dsc

    Thanks. Specially useful if you’re browsing a cifs mount, on which graphic file size visualizers like that konqueror plugin (I guess) don’t work.

    Just one suggestion, I think it goes better with the awk part as:

    awk ‘{ print $5 “: ” $8 }’ | sort

    with the file size first, followed by the file name (which in my case would be number 9, not 8 BTW), and then followed by “sort”, so you have it ordered by file size, which may be useful in helping to deal with the largest files first.

    • http://www.mkyong.com mkyong

      Thanks for your invaluable inputs.

  • Pingback: Problem mit HTTPD und Traffic - Server Support Forum()

  • Pingback: Tip: Como encontrar ficheros que ocupan mucho espacio en Linux « Command Line()

  • Pingback: Tip: Como encontrar ficheros que ocupan mucho espacio en Linux | Ayuda Linux()

  • Pingback: find command()