#!/usr/bin/perl -w # # pl - Version 0.2.1 # # Author : Ingo Strauch (strauch@mail.desy.de) # # Created : 20.03.2000 # Last update: 28.03.2000 # Download : http://www-users.rwth-aachen.de/Ingo.Strauch/pl # # This program lists all regular files in a directory along with their size. # The total amount of all files is given in kilobytes and bytes. Use it if # your system reports file sizes in 512 byte blocks (POSIX) and/or you don't # want to have links and directories in the sum. use integer; # So far only the following options are recognized: # # -a : list hidden files (default is no hidden files) # # 'path' : lists contents of the given path (default is current directory) die "You can only specify a path and/or the '-a' option!\nProgram terminated!\n\n" if (@ARGV > 2); $all=0; $verz = $ENV{'PWD'}; # simple 'command line parsing' ;-) while (@ARGV) { $current = shift; if ($current =~ /^\-/o) { # print "'$current' is a flag.\n"; if ($current eq '-a') { $all=1; } } elsif ($current =~ /^\//o) { # print "'$current' seems to be a directory.\n"; if (-d $current) { $verz = $current; } } elsif (-d $ENV{'PWD'}.'/'.$current) { $verz = $ENV{'PWD'}.'/'.$current; } else { # print "'$current' is of other type.\n"; } } $verz =~ s|/$||; # remove newline from path name #print "working directory is set to '$verz'\n"; #print "display hidden files = ",$all,"\n"; opendir (DIR, "$verz"); my @dateien = readdir DIR; closedir (DIR); if ($all == 1) { @gefiltert = grep !/^\.{1,2}$/, @dateien; # remove '.' and '..' from file list } else { @gefiltert = grep !/^\./, @dateien; # remove '.', '..' and all # hidden files from file list } @sortiert = sort @gefiltert; $groesse=0; $zahl=0; foreach $datei (@sortiert) { if (!(-d $verz.'/'.$datei) && !(-l $verz.'/'.$datei)) { ($dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $einzel, $dummy, $dummy, $dummy, $dummy, $dummy) = stat $verz.'/'.$datei; format STDOUT = @######## @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $einzel, $datei . write STDOUT; $groesse += $einzel; $zahl++; } } print "\ntotal: ", $groesse/1024 , " KBytes (",$groesse,") in ",$zahl," files\n";