From af0347d903047ce08111d670e7f1e7256452e8a3 Mon Sep 17 00:00:00 2001 From: hjp Date: Wed, 28 Jan 1998 21:16:17 +0000 Subject: [PATCH] Initial release. --- waste/GNUmakefile | 8 ++++++ waste/waste | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 waste/GNUmakefile create mode 100755 waste/waste diff --git a/waste/GNUmakefile b/waste/GNUmakefile new file mode 100644 index 0000000..0105040 --- /dev/null +++ b/waste/GNUmakefile @@ -0,0 +1,8 @@ +include GNUmakerules + +all: waste + +errno: +clean: + rm waste +install: $(BINDIR)/waste diff --git a/waste/waste b/waste/waste new file mode 100755 index 0000000..a888dea --- /dev/null +++ b/waste/waste @@ -0,0 +1,73 @@ +#!/usr/local/bin/perl + +# +# Report wasted space. +# +# This basically prints a list of files and directories below a +# start point, where each entry is tagged with a "waste factor". +# The waste factor is a weighted sum of size, mtime and atime +# of the file. +# + +sub wastefactor { + my ($size, $mtime, $atime) = @_; + + return $size * $sf * ($mtime * $mf + $atime * $af); +} + + +sub waste { + my ($dir) = @_; + my $i; + my @files; + my ($mtime, $atime, $size); + my ($tmtime, $tatime, $tsize) = (0, 0, 0); + + if (!opendir(DIR, $dir)) { + printf "$0: cannot open directory $dir: $!\n"; + return; + } + @files = readdir(DIR); + closedir(DIR); + foreach $i (@files) { + if ($i eq "." || $i eq "..") { next } + + $filename = $dir . "/" . $i; + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) = + stat($filename); + + if (-d _) { + ($size, $mtime, $atime) = waste($filename); + } else { + printf "%10.0f %d %d %d %s\n", + wastefactor( + $size, ($now - $mtime), ($now - $atime)), + $size, ($now - $mtime), ($now - $atime), + $filename; + } + $tsize += $size; + if ($mtime > $tmtime) {$tmtime = $mtime;} + if ($atime > $tatime) {$tatime = $atime;} + } + printf "%10.0f %d %d %d %s\n", + wastefactor( + $tsize, ($now - $tmtime), ($now - $tatime)), + $tsize, ($now - $tmtime), ($now - $tatime), + $dir; + return ($tsize, $tmtime, $tatime); +} + +### --- main --- ### +$sf = 1.0/1000; +$mf = $af = 1.0/(3600*24*365.25); + +if ($#ARGV != 0) { + print "Usage: $0 directoryname\n"; + exit(1); +} + +$now = time(); + +waste($ARGV[0]); +exit(0);