Find big files

By jbayer - Last updated: Wednesday, October 2, 2013 - Save & Share - 4 Comments

Someone is using a lot of space, and you want to find out who.  More specifically, you would like to identify the large files and automatically send them an email about it.

This script will do that for you.  It’s called findbig, and can be called by hand or from a cron job.  It will only send one email to a user, with a list of all large files in it.  It sends mail to the local user account, if you want the user’s mail sent to a different address, you will have to either edit the file or use the /etc/aliases file to redirect the email.

The parameters are:

findbig [ - a age ] [ -c ] [ -m addr ] [ -l log ] [ -u ] [ -d ] [ -s size ] [-e dir] [-x filename] [dir [size] ]
-a age   Minimum age, in days
-c       console mode, echo all messages to screen
-d       Debug mode
-s size  Minimum size of files to report
-e dir   Directory to exclude
-m addr  Email address to send all messages to
-l log   Append results to this file
-u       Send mail to owner
-x filename filename containing directories and files to exclude. The file contains
one path or file per line. Directories are identified by a trailing slash
Comments begin with a pound sign (#)
dir Directory or file to work on
size Minimum size of files to report. Suffixes are allowed (k for K, m for meg,
g for gig, t for tera). Both lower and upper case are allowed



An example (broken up onto 2 lines):

findbig  -a 10 -m -e /var/lib/libvirt/images \
         -e /proc -l /home/jbayer/bin/test.log  -u  / 10g

And this does the following:

  1. Send emails to me of found files
  2. Send emails to the owner of the file
  3. Exclude the following directories:
    1. /var/lib/libvirt/images
    2. /proc
  4. Log results in the file /home/jbayer/bin/test.log
  5. Start in the / directory
  6. Find all files bigger than 10 gig in size, and at least 10 days old


  findbig.tar.gz (2.2 KiB, 384 hits)

Posted in Bash • Tags: , Top Of Page

4 Responses to “Find big files”

Comment from makksi
Time October 18, 2013 at 8:44 am

I found very useful your program!

I would like also to know if you have a version of executable which sorts files before sending email and also limit number of files to be reported.

Thanks a lot


Comment from makksi
Time October 21, 2013 at 6:53 am

Can you also tell me if there is a configuration file where I can put some email alias to the owner of big files?

Comment from jbayer
Time December 13, 2013 at 7:46 pm

It sends email to the userid on the system of the owner of the files. If you want aliases, you can add them to the /etc/aliases file

Comment from jbayer
Time December 13, 2013 at 7:52 pm

The list already is sorted. But the entire path is part of the sort.

There is no limit on the number of files. If you would want to do that, you can modify it at lines 206-207, pipe the output through head as follows:

{FIND} $1 ${minage} ${prune} -type f -size +${size}k -exec ls -lh {} \; | awk ‘{ print $3 ” ” $9 ” ” $5 }’ | sort | head -${maxlines} >$tmpfile

Write a comment