How to find files that are eating up disk space

Karl Vogel vogelke+software at
Wed Dec 17 19:18:55 UTC 2008

>> On Wed, 17 Dec 2008 12:16:57 -0500, 
>> John Almberg <jalmberg at> said:

J> Is there a command line tool that will help me figure out where the [disk
J> space] problem is?

   I run a script every night to handle this.  We have a few business
   divisions, and each division has several groups sharing files
   via Samba.  Each group likes its own space with permissions that
   prevent file diddling by other groups.  For example, division 3 is
   on drive /rd04, and has group directories /rd04/div3/engineering,
   /rd04/div3/finance, and /rd04/div3/marketing.


      # dirsize: see how big each top-level group directory is.


      umask 022
      tag=`basename $0`
      host=`hostname | cut -f1 -d.`

      logmsg () {
          logger -t "$tag" "$@"

      # Check group areas on each drive.


          for dir in $list
              logmsg checking size of $dir
              find $dir -type d -maxdepth 1 -print |
                  tail +2 | sort | xargs du -s

      ) | mailx -s "$tag: directory sizes on $host" root

      logmsg done
      exit 0

J> Even better, is there a way to proactively monitor the file system, so I
J> can fix problems before I start getting 'out of disk space' errors?

   This script is run hourly to tell me if we completely run out of room
   on something like /var or one of the user drives.  I run it on BSD and
   Solaris boxes, so I try to avoid GNU or OS dependencies.


      # checkdrives: send mail if a filesystem gets too full

      export PATH

      # Portability stuff here.

      case "`uname -s`" in
          SunOS)    DF='/usr/xpg4/bin/df -F ufs -k' ;;
          FreeBSD)  DF='/bin/df -t ufs -k' ;;
          *)        DF='df' ;;

      # "Too full" means 99% and less than 100 Mbytes available.

      str=`$DF |                      # Check filesystem size ...
        tail +2 |                     # ... skip the header ...
        tr -d '%' |                   # ... kill the percent sign ...
        awk '$4 < 100000 && \
             $5 >= 99 {print $6}'`    # ... and print the filesystem.

      case "X$str" in
          X)  ;;
          *)  $DF $str | mailx -s 'Filesystem getting full' root ;;

      exit 0
Karl Vogel                      I don't speak for the USAF or my company
It only rains straight down.  God doesn't do windows.   --Steven Wright

More information about the freebsd-questions mailing list