#!/usr/bin/perl -s # filetrack {-h | -H} file $p = 1024; if ($H) { $h = 1; $p = 1000 } $| = 1; # this forces a flush after every print $f = $ARGV[0]; # this is the name of the file $s = ( stat $f )[7]; # this is the size of the file $t = time; # this is the time defined $f || die "filetrack: no file name provided\n"; while ( sleep 1 ) { # we're going to print the following information printf "\r$f %s bytes at %.2f Kb/s", # the size the file is occupying now $_ = h( ( stat $f )[7] ), # and the rate at which it has been increasing (sort of) ( $_ - h($s) ) / $p / ( time - $t ); } sub h { $h || return $_[0]; my $n = $_[0]; my $m; for ( 'k', 'M', 'G', 'T' ) { $n > $p || last; $m = $_; $n = int( $n / $p ); } return "$n$m"; }