This program featured online in UnixReview.com, Shell Corner, Hosted by Ed Schaefer, April 2005. |
|||||||||||||
http://www.OrlandoKuntao.com
|
|||||||||||||
Finding Large Files With Biggest.sh
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 biggest.sh. Biggest.sh 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 biggest.sh like this: biggest.sh -l 10 /usr. This returns the ten biggest files in /usr. Biggest.sh 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), biggest.sh comes with six additional options. Here is the usage listing with a brief description of each.
Usage: biggest.sh -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 argumentOptions |
|||||||||||||
|
|||||||||||||
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!). Description
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 biggest.sh 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. |
©Copyright Bob Orlando, 1995-2016 All rights reserved. |
http://www.OrlandoKuntao.com E-mail: Bob@OrlandoKuntao.com |
Last update:
Feb. 2, 2016 by Bob Orlando |