Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Unix find tutorial

Prev | Contents | Next

Part 8: Finding Files based on size: largest, empty and within certain range

Among categories of files with specific sizes the most popular are probably zero-length file and "huge files".

Zero length files formally might be considered a subclass of abnormal files but in reality they are often used in software installations.  Do not try to delete them unless you understand what you are doing. 

Here is some examples:

As with abnormal files discussed in previous section it is important to exclude certain parts of the directory tree from searching.  You can use all approaches discussed in section 6 but often more practical and more simple to use a small Perl script to weed "junk" directories.  For example:

#!/usr/bin/perl
open(SYSLOG,"find / -type f -size 0 -ls|");
@pattern=(
 "/var/spool/",
 "/var/tmp/",
 "/var/locks/",
 "/var/ct/",
 "/var/ifor/",
 "/usr/lpp/",
 "/usr/omni/log/debug.log",
 "/tmp/",
 "/proc/", 
 "/.swdis/",
 "/etc/Tivoli/tec/",
 "/usr/omni/lib/perl",
 "/opt/TMF/db/nti2171.db/",
 "/opt/tivoli/EPProxy/",
 "/opt/tivoli/TWS/stdlist/",
 "/var/adm/logs/",
 "/oracle/app/oracle/product/9.2.0/",
 "/oracle/app/oracle/product/9.2.0_OLD/",
 "/usr/opt/perl5/lib/5.8.2/aix-thread-multi/",
 "/usr/opt/perl5/lib64/5.8.2/aix-thread-multi-64all/",
 "/usr/opt/perl5/lib/site_perl/5.8.2/",
 "/usr/lib/objrepos/",
 "/usr/aix/_AIX_print_subsystem",
 "/etc/ipsec/inet/DB/",
 "/etc/objrepos/"
 );
while() {
   $data=$_;
   $line=substr($data,65);
   chomp($line);
   $found=0;
   foreach $string (@pattern) {
      if ( index($line,"$string") > -1 ) {
         $found=1;
         last;
      }
   }	
   if ($found == 0 ) {print "$data\n";}
}  

Prev | Contents | Next


Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Created: May 16, 1997; Last modified: August 25, 2009