Linux Find Large Files

Q. How do I find out all large files in a directory?

A. There is no single command that can be used to list all large files. But, with the help of find command and shell pipes, you can easily list all large files.

Linux List All Large Files

To finds all files over 50,000KB (50MB+) in size and display their names, along with size, use following syntax:

Syntax for RedHat / CentOS / Fedora Linux

find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Search or find big files Linux (50MB) in current directory, enter:
$ find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Search in my /var/log directory:
# find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Syntax for Debian / Ubuntu Linux

find {/path/to/directory} -type f -size +{file-size-in-kb}k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Search in current directory:
$ find . -type f -size +10000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Sample output:

./.kde/share/apps/akregator/Archive/http___blogs.msdn.com_MainFeed.aspx?Type=AllBlogs.mk4: 91M
./out/out.tar.gz: 828M
./.cache/tracker/file-meta.db: 101M
./ubuntu-8.04-desktop-i386.iso: 700M
./vivek/out/mp3/Eric: 230M

Above commands will lists files that are are greater than 10,000 kilobytes in size. To list all files in your home directory tree less than 500 bytes in size, type:
$ find $HOME -size -500b
OR
$ find ~ -size -500b

To list all files on the system whose size is exactly 20 512-byte blocks, type:
# find / -size 20

Perl hack: To display large files

Jonathan has contributed following perl code print out stars and the length of the stars show the usage of each folder / file from smallest to largest on the box:

 du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf  ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'

ls command: finding the largest files in a directory

You can also use ls command:
$ ls -lS
$ ls -lS | less
$ ls -lS | head +10

ls command: finding the smallest files in a directory

Use ls command as follows:
$ ls -lSr
$ ls -lSr | less
$ ls -lSr | tail -10

You can also use du command as pointed out georges in the comments.

See more find command examples and usage here and here.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 10 comments… read them below or add one }

1 Scott Carlson 12.16.08 at 8:55 pm

I use a script with this…

find . -xdev -printf ā€˜%s %p\n’ |sort -nr|head -20

2 Vivek Gite 12.16.08 at 9:06 pm

Excellent scott!

3 georges 12.16.08 at 9:07 pm

What I use is much simpler and efficient I’m afraid:
du -xak .|sort -n|tail -50

it lists the 50 biggest files or directories sorted by size

4 Shatnanu Oak 12.17.08 at 8:56 am

Poor man’s command.
ls -lhR | grep 'G '
Not perfect but let me know the big files more than 1 GB

5 Topper 12.17.08 at 12:24 pm

ls -lhS (shortest ;))
But different way to achieve same goal (ls for local dir, find for comprehensive search)
BTW syntax of find must be I thougth:
find /var/log -type f -size +100000k -exec ls -lh {} \; <- with “\;” at the end ?

6 Vivek Gite 12.17.08 at 12:37 pm

Topper,

Dam html… thanks for the heads up.

7 Jonathan Jiang 12.17.08 at 3:44 pm

I prefer this perl script feeding from a du -k :

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf                 ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'

It’ll print out stars and the length of the stars show the usage of each folder / file from smallest to largest on the box. Enjoy!

8 Jonathan Jiang 12.17.08 at 3:49 pm
du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf                 ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'
9 Vivek Gite 12.17.08 at 5:37 pm

Jonathan,

Thanks for sharing your nifty perl code. The faq has been updated with your code.

10 Chris Giordano 01.27.09 at 6:23 pm

If using RedHat 6.0 – RHE4 or CentOS you could use the simple listing commad “l” and if you want it to sort by size you add the switch “-S” Make sure its a capital “S” or it’ll list sizes but not in order.

l -S
this will return everything in that directory from largest to smallest.

if you want to do listing in a directory and need to figure out the switch you could also do “l –help” this will bring up the help file for the listing command.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , ,

Previous post: MySQL Bin Files Eating Lots of Disk Space

Next post: Windows Delete File Securely / Permanently Delete File Data