This program featured online in, Shell Corner, Hosted by Ed Schaefer, April 2005.
Finding Large Files With 
by Bob Orlando

How many times has a file system filled up causing you to spend more time than you liked finding that hernia file or files?  I'll wager more times than you care to remember.  After living with that aggravation for way too long, I put together searches a given file system and lists the biggest files it finds in size order -- biggest first -- displaying up to 500 lines of output.  Five hundred lines of output may be a bit much, but biggest comes with a suite of options, one of which ( -l ) allows you to specify precisely how many lines you want returned.  We do exactly that with our monitoring software.  When a file system reaches alert level, we have the monitoring program call like this: -l 10 /usr.  This returns the ten  biggest  files in /usr. has run successfully on Sun Solaris and Linux.  It is written in Bourne shell (instead of Korn or Bash) for one reason only -- portability.  The script runs under Bourne, Korn, and Bash environments without modification.

Besides the lines ( -l ) option (already shown), comes with six additional options.  Here is the usage listing with a brief description of each.

      Usage: -fHh -l <nn> -v -t <dir> -s <nnn> fs
                        -f = Follow links
                        -H = Displays detailed documentation
                        -h = Provides usage brief
                        -l = Displays <nn> lines (default is 500)
                        -s = Minimum file size is <nnn> (default is 500K)
                        -t = Use <dir> as temp/work directory (default is /var/tmp)
                        -v = Edit (vi) file list
                        fs = Required file system argument
-f  My experience with this link-following option is that it is used only rarely.  Frequently followed links often turn into wild goose chases on mounted or remote drives.  However, for those times where this capability is necessary, link following ( -f ) is your option.
-H  Detailed documentation is available for those wanting more than just the usage brief.
-h  Provides a usage brief that lists the command and its options as shown above.
-s  Specified in K-bytes, this option allows the user to specify a greater minimum file size than the 500K default.
-t  To specify a working directory other than the /var/tmp default, use the  -t  option (i.e.,  -t $HOME/temp ).  This "option" may be critical when the offending file system is /var/tmp, again, our default working directory.
-v  If you prefer seeing the result in  vi  instead of having it scroll up the screen, then use this  -v  (verbose) option.

The file system specified must be a local file system. This is enforced by use of the display file systems ( df ) command  -l  or local option.  This prevents us from searching through a remotely mounted file system (a real wild goose chase!).

Using the find command, descends through the specified file system listing all files whose sizes exceed either the default minimum size (500K) or the minimum value provided via size ( -s ) option.  The file list is created in /var/tmp by default as it usually much larger than /tmp.  However, in the event that /var is the file system that's full (or is not writable to the user), the temp dir ( -t ) option is available to redirect the output elsewhere.

When root is the directory being searched, -xdev is supplied automatically as a  find  command argument so only the root directory, and none of its subdirectories, is searched.  Without  -xdev , you can easily find a file in another directory (and possibly another file system) that is larger than the file that is actually the culprit.

Remember that a file system can fill up in other ways; for example, instead of the culprits being one or two hernia files, the real problem may be a directory with many large files, none of which is the biggest.

For that, I recommend the use of  dispus, a Perl program developed by Scott Rochford that traverses disks locating the directories that are the fullest.  Between and  dispus,  if you cannot find the the offending files, then they are probably your own files and you really don't want to see them listed anyway.

Artificial  intelligence  is  no  match  for  natural  stupidity.
©Copyright Bob Orlando, 1995-2016
All rights reserved.
Last update:  Feb. 2, 2016
by Bob Orlando
Web Site of Bob Orlando: Instructor in Kuntao-Silat (Chinese kuntao and Dutch-Indonesian pukulan pentjak silat), author of two popular martial art books: "Indonesian Fighting Fundamentals" and "Martial Arts America: A Western Approach to Eastern Arts"; and producer of four martial art videos: Fighting Arts of Indonesia, Reflex Action, Fighting Footwork of Kuntao and Silat, Fighting Forms of Kuntao-Silat. Offering practical martial arts instruction to adults living in and throughout the Denver metropolitan area including, Lakewood, Littleton, Morrison, and Golden Colorado.