#!/usr/bin/perl -w # zstrip by zentara@highstream.net # ©2/22/2002 copyright #-usage: zstrip topdir test(optional) ; zstrip will recursively do a directory, defaults to '.' #-runs 'strip' on all system binary executables and .so files #-excludes .a and .o files and misc non-executable binaries such as graphics #-skips /proc, /boot and /home, will hang if run on /proc #-remove the /home in the match test to use in /home #-makes shared libraries faster to load, and use less memory #-recovers harddrive space from unstripped files, space recovered is reported #-log all output to file zstrip.log # This code is distributed under the GNU General Public License (GPL). See # http://www.opensource.org/gpl-license.html and http://www.opensource.org/. # USE AT YOUR OWN RISK, ALWAYS MAKE BACKUPS FIRST use strict; use File::Find; use Cwd; my $tot = 0; my ($topdir,$testmode) = @ARGV; if ($topdir eq '.'){$topdir = cwd()} if ((!defined $topdir) or !(-d $topdir)) { print 'You have not entered a directory. Usage: zstrip topdir test (optional, will only print found files) Default-> will run in testmode in current directory. Continue? (n)/y '; if (=~ /^[yY]/) {$topdir = cwd(); $testmode = 1; &strip}} if (defined $testmode){ print "Running test on $topdir, continue? (n)/y "; if ( =~ /^[yY]/){&strip} else {exit}} else {print "Running real strip on $topdir, continue? (n)/y "; if ( =~ /^[yY]/){&strip} else {exit}} exit; sub strip{ open (STRIPLOG,"+>zstrip.log"); select STRIPLOG; open STDERR, ">&STRIPLOG" or die "Can't capture STDERR"; find (\&found, $topdir); print 'Total space recovered is ',$tot,"\n"; close STRIPLOG; select STDOUT; print 'Total space recovered is ',$tot,"\n"; close STDERR; exit; } sub found { my $file = $File::Find::name; if ($file =~ m#^(/proc|/boot|/home)#) {return} return unless -f; return if -l; if ($file =~ m/(\.o|\.a|\.la|\.bmp|\.xpm|\.gif|\.png|\.jpg|\.jpeg|\.ico|.\avi|\.mpg|\.mp3|\.wav|\.gz|\.tgz|\.z|\.Z|\.bz2|\.tar)$/) {return} if ((/\.so/) or (-B and -x)){ my $s = -s $file; print "$file\t$s\t "; unless(defined $testmode){system "strip $File::Find::name"} my $s1 = -s $file; print $s - $s1,' stripped',"\n"; $tot += ($s - $s1); }}